Skip to content
Advertisement

Transform JSON into required format

Here is my input JSON

JavaScript

I need to transform json w.r.t parent category and what ever child json elements w.r.t parent to be in one format. All should be dynamic no hard coding comparing with strings.

Need to transform my input json to below sampleformat,

JavaScript

I tried separating parents and child values in an array and loop it and push. But not succeeded. Please suggest me how can i transform my input json to required output json format.

JavaScript

But from here, am not getting any idea how to transform my data into my desired json

Advertisement

Answer

This is prefect for me:

JavaScript

This is what I suggest to you if you really need an object in "date" property:

JavaScript

This is what you actually want (There is also an result as in previous Code Snipept. You can get it by typing resultMap instead of resultArr at the end):

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement