2017-03-25 13:10:12 -05:00
|
|
|
|
# json.sh
|
2017-03-25 15:23:10 -05:00
|
|
|
|
json.sh is a very portable JSON parser--
|
|
|
|
|
it should work in just about any shell you throw at it.
|
2024-01-28 23:24:55 -06:00
|
|
|
|
It can parse and output variables from a JSON file in
|
|
|
|
|
a more script-friendly form.
|
2017-03-25 15:23:10 -05:00
|
|
|
|
|
2024-01-28 23:24:55 -06:00
|
|
|
|
This is an old hacked-together script of mine that I’m only posting because I’m sentimental.
|
|
|
|
|
Don’t use it; I would instead recommend the beautiful program [gron](https://github.com/tomnomnom/gron).
|
2017-03-25 15:23:10 -05:00
|
|
|
|
|
|
|
|
|
Usage
|
|
|
|
|
-------
|
|
|
|
|
To use json.sh, you can simply run `json.sh` with a filename as an argument.
|
|
|
|
|
Here's an example command and it's output:
|
2017-03-25 15:28:26 -05:00
|
|
|
|
```
|
|
|
|
|
$ sh json.sh example.json
|
2017-03-25 15:23:10 -05:00
|
|
|
|
/animals
|
|
|
|
|
/animals/pig
|
|
|
|
|
/animals/pig/tail
|
|
|
|
|
/animals/pig/tail = curly
|
|
|
|
|
/animals/pig/nose
|
|
|
|
|
/animals/pig/nose = adorable
|
|
|
|
|
/animals/sheep
|
|
|
|
|
/animals/sheep/tail
|
|
|
|
|
/animals/sheep/tail = short
|
|
|
|
|
/animals/sheep/nose
|
|
|
|
|
/animals/sheep/nose = ugly
|
2017-03-25 15:27:20 -05:00
|
|
|
|
```
|
2017-03-25 15:23:10 -05:00
|
|
|
|
|
|
|
|
|
There are also a few useful arguments you should keep note of:
|
2017-03-25 15:27:20 -05:00
|
|
|
|
|
2017-03-25 15:23:10 -05:00
|
|
|
|
| argument | description |
|
|
|
|
|
| --- | --- |
|
2017-03-25 15:27:20 -05:00
|
|
|
|
| `-v $string` | Only print variables with the name `$string`. |
|
|
|
|
|
| `-s $string` | Only print the value of the variable `$string`. |
|
|
|
|
|
| `-V $string` | Only print variables with the value `$string`. |
|
|
|
|
|
| `-o $string` | Only print the object `$string`. |
|
2017-03-25 15:23:10 -05:00
|
|
|
|
|
|
|
|
|
With `-v` and `-s`, for example, `$string` could be anything from `tail` to `/pig/tail` to `/animals/pig/tail`.
|
|
|
|
|
Same syntax goes for `-o`. `-V` is the only odd one out-- it's `$string` needs to be a variable's value, like `adorable` from `/pig/nose`.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Licensing
|
|
|
|
|
-----------
|
2017-03-25 15:27:20 -05:00
|
|
|
|
All of json.sh is released under the
|
2017-03-25 15:23:10 -05:00
|
|
|
|
[ISC](https://opensource.org/licenses/ISC) license.
|
|
|
|
|
|