https://github.com/pmunin/jsontransformation
https://github.com/pmunin/jsontransformation
Last synced: 11 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/pmunin/jsontransformation
- Owner: pmunin
- License: mit
- Created: 2019-06-18T22:41:59.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2022-12-08T05:43:03.000Z (over 3 years ago)
- Last Synced: 2025-07-30T03:09:26.628Z (11 months ago)
- Language: C#
- Size: 15.6 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: readme.md
- License: LICENSE.md
Awesome Lists containing this project
README
[](https://www.nuget.org/packages/JsonTransformation/)
[](https://ci.appveyor.com/project/pmunin/jsontransformation)
# What is this
.NET Standard library allows to transform source [Newtonsoft.Json.Linq.JToken](https://www.newtonsoft.com/json/help/html/T_Newtonsoft_Json_Linq_JToken.htm) object recursively using extendable "Transformers"
Note: Current implementation actually MUTATES source node provided for transformation
## Examples:
### Loading linked files:
```
//entryFile.json:
{
"linkedFile": { "$file": "shared.json" }
}
///shared.json:
{
"myFile2Prop1": 123
}
// new JsonTransformationService(new LoadFileTransform()).Transform(entryFileJToken):
{
"linkedFile": {
"myFile2Prop1": 123
}
}
```
### Merging by jpath:
```
//file.json:
{
"templates": {
"t1": {
"tp1": 123,
"tp2": "Hello world"
}
},
"jobs": {
"job1": {
"job1Prop1": 1235,
"$merge": "$.templates.t1"
}
}
}
//new JsonTransformationService(new MergeTransform()).Transform(fileJToken.SelectToken("$.jobs.job1"));
{
"job1Prop1": 1235,
"tp1": 123,
"tp2": "Hello world"
}
```
### Setting Parameters:
```
// file.json:
{
"templates": {
"t1": {
"name": { "$useParameter": "jobName" },
"tp1": 123,
"tp2": "Hello world"
}
},
"jobs": {
"job1": {
"job1Prop1": 1235,
"$merge": "$.templates.t1",
"$setParameters": {
"jobName": "My Job 1"
}
}
}
}
//new JsonTransformationService( new MergeTransform(), new ParametersTransform())
// .Transform(fileJToken.SelectToken("$.jobs.job1")):
{
"job1Prop1": 1235,
"name": "My Job 1",
"tp1": 123,
"tp2": "Hello world"
}
```
## Extensibility
If you need additional transformers, just implement interface ICanTransformJson and add it in ctor parameters of your jsonTransformationService instance.
## Installation
Use nuget package: https://www.nuget.org/packages/JsonTransformation/