I'm looking to use jq to automatically resolve any field which contains json as json, example:
Input
{
"guaranteedPrizes": "[]",
}
Output
{
"guaranteedPrizes": [],
}
For a generic solution, you might wish to consider walk/1
, and for efficiency, avoid calling fromjson
redundantly:
walk(if type == "string"
then . as $x | try fromjson catch $x
else . end)
If you want to go off the “deep end” and try evaluating fromjson recursively:
def deep:
walk(if type == "string"
then . as $x
| try (fromjson | deep)
catch $x
else . end);
deep
I'm looking to use jq to automatically resolve any field which contains json as json, example:
Input
{
"guaranteedPrizes": "[]",
}
Output
{
"guaranteedPrizes": [],
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.