40 lines
1.3 KiB
Plaintext
40 lines
1.3 KiB
Plaintext
|
JSON=../../lib/json.js
|
||
|
|
||
|
echo '{"name":"Trent","id":12,"email":"trent@example.com"}' | $JSON name email
|
||
|
|
||
|
|
||
|
echo ""
|
||
|
echo '[{"name":"Trent","id":12,"email":"trent@example.com"},
|
||
|
{"name":"Mark","id":13,"email":"mark@example.com"}]' \
|
||
|
| $JSON -a name email
|
||
|
|
||
|
|
||
|
# This happens because the input object is converted to an array with
|
||
|
# a single item. Then handled with '-a' array-processing.
|
||
|
echo ""
|
||
|
echo '{"name":"Trent","id":12,"email":"trent@example.com"}' | $JSON -a name email
|
||
|
|
||
|
|
||
|
echo ""
|
||
|
echo '[{"name":"Trent","id":12,"email":"trent@example.com"},
|
||
|
{"name":"Mark","id":13,"email":"mark@example.com"}]' \
|
||
|
| $JSON -d, -a name email # TODO: how to spec '\0' as delim (a la -print0)?
|
||
|
|
||
|
# Delims (issue #26)
|
||
|
echo ''
|
||
|
echo '# comma'
|
||
|
echo '[{"name":"trent","age":38},{"name":"ewan", "age":4}]' | $JSON -a name age -d ,
|
||
|
echo '# tab'
|
||
|
echo '[{"name":"trent","age":38},{"name":"ewan", "age":4}]' | $JSON -a name age -d '\t'
|
||
|
echo '# newline'
|
||
|
echo '[{"name":"trent","age":38},{"name":"ewan", "age":4}]' | $JSON -a name age -d '\n'
|
||
|
echo '# nul to xargs'
|
||
|
echo '[{"name":"trent","age":38},{"name":"ewan", "age":4}]' | $JSON -a name age -d '\0' | xargs -0 && echo 'end-of-xargs-output'
|
||
|
|
||
|
echo ""
|
||
|
echo '[{"foo": "bar"}, {"foo": "baz"}]' | $JSON -a
|
||
|
echo '[{"foo": "bar"}, {"foo": "baz"}]' | $JSON -a foo
|
||
|
|
||
|
echo ""
|
||
|
echo '[{"foo": "bar"}, {"foo": "baz"}]' | $JSON -aj foo
|