Both command line utilities allow to JSON output from a shell.
jo string=name integer=1457081292 float=12.3456 float2=1e-5 nil= boolean=true
{"string":"name","integer":1457081292,"float":12.3456,"float2":1e-05,"nil":null,"boolean":true}
Note that jo
preserves key order
jg string=name integer=1457081292 float=:12.3456 float2=:1e-5 nil=:null boolean=:true
{"boolean":true,"float":12.3456,"float2":1e-05,"integer":"1457081292","nil":null,"string":"name"}
Note that jg
sorts keys alphabetically
jo
keeps all the keys (and generates invalid JSON as per rfc4627 The names within an object SHOULD be unique.)
jo a=1 a=2 a=3
{"a":1,"a":2,"a":3}
jg
merge keys and last key wins (it's the same what jq
does parsing JSON)
jg a=1 a=2 a=3
{"a":"3"}
jo -a 1 2 3
[1,2,3]
seq 3 | jo -a
[1,2,3]
jo array[]=1 array[]=2 array[]=3
{"array":[1,2,3]}
jg [:1 :2 :3]
[1,2,3]
jg array=[:1 :2 :3]
{"array":[1,2,3]}
jo -a $(jo id=1) $(jo id=2)
[{"id":1},{"id":2}]
jg [id=:1 id=:2]
[{"id":1},{"id":2}]
jo a=$(jo a=1 b=2) b=$(jo a=3 b=4)
{"a":{"a":1,"b":2},"b":{"a":3,"b":4}}
jo a[a]=1 a[b]=2 b[a]=3 b[b]=4
{"a":{"a":1,"b":2},"b":{"a":3,"b":4}}
jg a={a=:1 b=:2} b={a=:3 b=:4}
{"a":{"a":1,"b":2},"b":{"a":3,"b":4}}
jg a.a=:1 a.b=:2 b.a=:3 b.b=:4
{"a":{"a":1,"b":2},"b":{"a":3,"b":4}}
jg a.b.c=value
{"a":{"b":{"c":"value"}}}
jo bool@T
{"bool":true}
jo bool@F
{"bool":false}
jo bool@t
{"bool":true}
jo bool@f
{"bool":false}
jo bool@1
{"bool":true}
jo bool@0
{"bool":false}
cat a
[email protected]
jo email=@a encoded=%a
{"email":"[email protected]","encoded":"ZWlyaUBlaXJpLmNhCg=="}
jg {key=a} {key=b}
{"key":"a"}
{"key":"b"}
jg [key=a] [key=b]
[{"key":"a"}]
[{"key":"b"}]
jo
is more convinient when you need to work with files and pipes. jq
works better with deep objects and multiline JSON