I have a json like this:
{"a.json": "....", ....}
The "..."
can be either a json string (The fromjson
can decode it then) or it is something else, then it fails.
I want a jq
filter that outputs if json was found in the string like "{}"
{"a.json": {}, ....}
Or else if it was a string like "shh"
then it removes the ".json" from the field name:
{"a": "shh", ....}
There can be other fields in the object, keep them in place. Find all fields ending with .json
(like the a.json
) and do this operation for all of them! Thanks
When:
with_entries( select(.key|test("\.json$")) as $root | $root.value = $root.value as $sub | ($sub|try fromjson catch $sub))
This works for the value, but I cannot find a way to chnge the .key
in the catch
block.