Quantcast
Channel: Active questions tagged jq - Stack Overflow
Viewing all articles
Browse latest Browse all 657

How to transform JSON array elements recursively into objects using JQ filter

$
0
0

I want to transform this JSON

{"property": "value","array1": [        {"name": "A","propertyA1": "1","propertyA2": "2"        },        {"name": "B","propertyB1": "1","array2": [                {"name": "C","propertyC1": "1","propertyC2": "2"                }            ]        }    ]}

into that using a JQ filter.

{"property": "value","array1": {"A": {"propertyA1": "1","propertyA2": "2"        },"B" : {"propertyB1": "1","array2": {"C" : {"propertyC1": "1","propertyC2": "2"                }            }        }    }}

The difficulty is to make this work recursively. Moreover, only arrays whopossess an object with a property name should be considered. I had a few attempts butit already fails if I want to add a new property do the arrays (I know it's not possible,since it is an array).


Viewing all articles
Browse latest Browse all 657

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>