-
Notifications
You must be signed in to change notification settings - Fork 55
Home
Pull the latest JUST.NET from https://www.nuget.org Install-Package JUST
This is demonstrated with various examples in the source code. Once you install the nuget to your project you need to import the following namespace:-
using JUST;
Below is a simple C# code snippet that you can use to transform your JSON:-
string input = File.ReadAllText("Examples/Input.json"); //read input from JSON file.
string transformer = File.ReadAllText("Examples/Transformer.json"); //read the transformer from a JSON file.
string transformedString = JsonTransformer.Transform(transformer, input); // do the actual transformation.
JUST is a transformation language just like XSLT. It includes functions which are used inside the transformer JSON to transform the input JSON in a desired output JSON. This section describes the various functions present in JUST and how they can be used to transform your JSON.
Every JUST function starts with "#" character.
This function is used to extract the value of a given property. The value is extracted using JSON path of the property. For more information on how to use JSON path refer to :- http://www.newtonsoft.com/json/help/html/QueryJsonSelectTokenJsonPath.htm
Consider the input:-
{
"menu": {
"popup": {
"menuitem": [
{
"value": "Open",
"onclick": "OpenDoc()"
},
{
"value": "Close",
"onclick": "CloseDoc()"
}
]
}
}
}
Transformer:-
{
"result": {
"Open": "#valueof(
Output:-
{ "result":{"Open":null,"Close":"OpenDoc()"} }
This condition is used to evaluate and if-else condition.
ifcondition(condition expresson, evaluation expression, true result, false result).
All four of the parameters can be a 'valueof' expressions or constants.
Consider the input:-
{ "menu": { "id" : "github", "repository" : "JUST" } }
Transformer:-
{
"ifconditiontesttrue": "#ifcondition(#valueof(
Output:-
{"ifconditiontesttrue":"JUST","ifconditiontestfalse":"fail"}