JSon Utils
By default it will output a nicely formated json output
echo '{"a":1,"b":2,"c":[1,2,3]}' | jsu
Output :
{
"a": 1,
"b": 2,
"c": [
1,
2,
3
]
}
echo '{ "a":1, "b":2, "c":[1,2,3] }' | jsu -c
Output:
{"a":1,"b":2,"c":[1,2,3]}
echo '{"a":"{\"a1\":1}","b":["{\"w\":2}"]}' | jsu
Outputs:
{
"a": "{\"a1\":1}",
"b": [
"{\"w\":2}"
]
}
adding the -e flag will expand the embeded strings:
echo '{"a":"{\"a1\":1}","b":["{\"w\":2}"]}' | jsu -e
Outputs:
{
"a": {
"a1": 1
},
"b": [
{
"w": 2
}
]
}
'''echo 'some text {"a":1} more "text" [1,2,3] text [1,{"b":2}] text ' | jsu -x```
Outputs:
[
{
"a": 1
},
[
1,
{
"b": 2
}
]
]
Note: Extract looks for {} or [] sequences. For an array [] it must have an element that is a json object. Also note the output is not standard json. use the -w to wrap in a top level property.
'''echo 'some text {"a":1} more "text" [1,2,3] text [1,{"b":2}] text ' | jsu -x -w extracted```
Outputs:
{
"extracted": [
{
"a": 1
},
[
1,
{
"b": 2
}
]
]
}