Last active
December 7, 2019 16:36
-
-
Save jeiea/a6a132e3ff2006c7911070d0a28cd3a7 to your computer and use it in GitHub Desktop.
It extracts json structure with parsing string json and picking first element of array
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jq 'def r: walk(if type == "array" then if .[0] then [.[0]] else [] end else (fromjson? | r) // . end); r' a.json | |
# a.json | |
# { | |
# "array": [1,2,3], | |
# "nested_json": "{\"likes\": [1,2,3]}" | |
# } | |
# | |
# output | |
# { | |
# "array": [ | |
# 1 | |
# ], | |
# "nested_json": { | |
# "likes": [ | |
# 1 | |
# ] | |
# } | |
# } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment