I have this JSON:
{"item":2, "url":"domain/house/23/bedroom"}
I'm trying to use jq to obtain this new JSON:
{"item":2, "number":"23", "room":"bedroom"}
Is it possible to do this in JQ? As a first step, I tried to use the capture function to catch the substring after "/house/", but it doesn't work:
cat myjson.json | jq -c '{item:.item,substring:(.url | capture("/house/.*").substring)}'
Is there a way to extract both values and put them in two different fields?
Split url by slashes, and use the result for generating new fields.
{item} + (.url / "/" | {number: .[-2], room: .[-1]})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With