Root/
| 1 | . /lib/functions/jshn.sh |
| 2 | |
| 3 | # generating json data |
| 4 | json_init |
| 5 | json_add_string "msg" "Hello, world!" |
| 6 | json_add_object "test" |
| 7 | json_add_int "testdata" "1" |
| 8 | json_close_object |
| 9 | MSG=`json_dump` |
| 10 | # MSG now contains: { "msg": "Hello, world!", "test": { "testdata": 1 } } |
| 11 | |
| 12 | |
| 13 | # parsing json data |
| 14 | json_load "$MSG" |
| 15 | json_select test |
| 16 | json_get_var var1 testdata |
| 17 | json_select .. |
| 18 | json_get_var var2 msg |
| 19 | echo "msg: $var2 - testdata: $var1" |
| 20 |
