Skip to content

Transformation Issue - Dynamic JSON #309

@NJ2929

Description

@NJ2929

Hi team, I really need your help here as this will be live in 2 days.

I'm not able to achieve the nested loop feature and the code keeps failing, I'm fairly new to JUST.net, really looking for your help here.

My input JSON:

`{
	"entityDataStore": {
		"entityData": {
			"entityParent": {
				"NODE1": "dummy value",
				"NODE2": "dummy value",
				"NODE3": "dummy value",
				"NODE4": "dummy value",
				"entityParent-entityChild": [   
					{
						"Id1": "dummy value",
						"name": "dummy value",
						"entity": "dummy value",
						"ParentName": "dummy value" 
						 
					},
					{
						"Id1": "dummy value",
						"name": "dummy value",
						"entity": "dummy value",
						"ParentName": "dummy value" 
					}
				]
			}
		}
	}
}`

output, what I'm trying to achieve, is as the "entityParent-entityChild" has array of OBJECTS, so its dynamic in nature, I'm looking to recreate it as below:

Output JSON:


`{
	"newChanges": [
		{
			"dataMember": "entityParent-entityChild",
			"rows": [
				{
					"state": "New",
					"rowid": "1",
					"fields": [
						{
							"columnName": "name",
							"originalValue": null,
							"currentValue": "dummy value"
						},
						{
							"columnName": "entity",
							"originalValue": null,
							"currentValue": "dummy value"
						}
					]
				},
				{
					"state": "New",
					"rowid": "2",
					"fields": [
						{
							"columnName": "name",
							"originalValue": null,
							"currentValue": "dummy value"
						},
						{
							"columnName": "entity",
							"originalValue": null,
							"currentValue": "dummy value"
						}
					]
				}
			]
		}
	]
}`

My Transformation: (Currently I have written to fetch a column only to see, if it will work or not, sadly i get an error 'Unexpected character encountered while parsing path'


`{
  "entityDataStore": {
    "#loop($.entityDataStore.entityData.entityParent, rows)": {

      "fields": {
        "#loop($.entityParent-entityChild)": {
          "entity": "#currentvalueatpath($.entity)"
        }
      }
    }
  }
}
`

My C# code:

`                    
 string input = jsonResponse;
string createTransformation= File.ReadAllText("<file.JSON>");
 string transformedString = JsonTransformer.Transform(createTransformation, input);
`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions