Skip to content

pmunin/JsonTransformation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NuGet version (JsonTransformation) Build status

What is this

.NET Standard library allows to transform source Newtonsoft.Json.Linq.JToken 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/

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published