- Copy-paste this code and sample data.
- Get it to run
- Replace the input and spec file with your own
Available here.
using Jolt.Net;
using Newtonsoft.Json.Linq;
using System;
using System.IO;
namespace Sample
{
class Program
{
static JToken GetJson(string path)
{
path = Path.Combine($"../../../{path}".Split('/'));
return JToken.Parse(File.ReadAllText(path));
}
static void Main(string[] args)
{
var spec = GetJson("spec.json");
var input = GetJson("input.json");
Chainr chainr = Chainr.FromSpec(spec);
var transformedOutput = chainr.Transform(input);
Console.WriteLine(transformedOutput.ToString());
}
}
}Available here.
{
"rating": {
"primary": {
"value": 3
},
"quality": {
"value": 3
}
}
}Available here.
[
{
"operation": "shift",
"spec": {
"rating": {
"primary": {
"value": "Rating"
},
"*": {
"value": "SecondaryRatings.&1.Value",
"$": "SecondaryRatings.&.Id"
}
}
}
},
{
"operation": "default",
"spec": {
"Range" : 5,
"SecondaryRatings" : {
"*" : {
"Range" : 5
}
}
}
}
]With pretty formatting, looks like:
{
"Rating": 3,
"Range": 5,
"SecondaryRatings": {
"quality": {
"Id": "quality",
"Value": 3,
"Range": 5
}
}
}