SHON (SHell Object Notation)
SHON is a command line notation for JSON. SHON lends itself better to command line usage for the purposes of interpolating variables.
| Type | JSON | SHON |
|---|---|---|
| Object | {"hello": "World"} |
[ --hello World ] |
| Array | ["beep", "boop"] |
[ beep boop ] |
| Array | [1, 2, 3] |
[ 1 2 3 ] |
| Empty Array | [] |
[ ] or [] |
| Object | {"a": 10, b: 20} |
[ --a 10 --b 20 ] |
| Empty Object | {} |
[--] |
| Number | 1 |
1 |
| Number | -1 |
-1 |
| Number | 1e3 |
1e3 |
| String | "hello" |
hello |
| String | "hello world" |
'hello world' |
| String | "10" |
-- 10 |
| String | "-10" |
-- -10 |
| String | "-" |
-- - |
| String | "--" |
-- -- |
| True | true |
-t |
| False | false |
-f |
| Null | null |
-n |
SHON subexpressions can be interpolated with a bare $SHON variable.
$ ARRAY='[ 1 2 3 ]'
$ npx shon [ --array $ARRAY ]
{"array":[1,2,3]}
To safely interpolate an arbitrary string, use -- "$VARIABLE".
This ensures that the variable is interpreted as a string literal in place,
even if it begins with - or --.
$ STRING='-rf /'
$ npx shon [ --string -- "$STRING" ]
{"string":"-rf /"}
Try the SHON Playground!
Implementations #
- SHON in JavaScript
- SHON in Go
- SHON in Rust
- Of course, you should just use
jq, as illustrated in JISH.
Credits #
Abhinav Gupta contrived the name SHON, which is much better than JSON and the Arguments.