Skip to content
Advertisement

reformatting json file to have identifying attribute and array to accomodate for sub-objects

I am trying to reformat some relatively unstructured json to fit my needs, where I want each object to have a ‘name’ attribute as well as a ‘children’ array for sub-objects. I have a json file that looks like below:

JavaScript

I would like to format it to be something like this:

JavaScript

How would I be able to do this recursively using pure js, in the case that objects can have a different depths of subobjects? Or is it still possible to do it iteratively?

Thanks in advance!!!

Advertisement

Answer

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