Search code examples
jsonnestedevaljqfromjson

Use jq to interpret nested JSON in JSON


I'm looking to use jq to automatically resolve any field which contains json as json, example:

Input

{
  "guaranteedPrizes": "[]",
}

Output

{
  "guaranteedPrizes": [],
}

Solution

  • 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)