close
Skip to content

decibel/JSON.sh

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

106 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JSON.sh

yo, so it's a json parser written in bash

pipe json to it, and it traverses the json objects and prints out the path to the current object (as a JSON array) and then the object, without whitespace.

$ json_parse < package.json
["name"]  "JSON.sh"
["version"]  "0.0.0"
["description"]  ""
["homepage"]  "http://github.com/dominictarr/JSON.sh"
["repository","type"]  "git"
["repository","url"]  "https://github.com/dominictarr/JSON.sh.git"
["repository"]  {"type":"git","url":"https://github.com/dominictarr/JSON.sh.git"}
["bin","json_parse"]  "./JSON.sh"
["bin"]  {"json_parse":"./JSON.sh"}
["dependencies"]  {}
#  ... etc

a more complex example:

curl registry.npmjs.org/express | ./JSON.sh | egrep '\["versions","[^"]*"\]'
... try it and see

Options

-b

Brief output. Combines 'Leaf only' and 'Prune empty' options.

-f format

Output format. See below.

-l

Leaf only. Only show leaf nodes, which stops data duplication.

-p

Prune empty. Exclude fields with empty values.

-n

No-head. Don't show nodes that have no path. Normally these output a leading '[]', which you can't use in a bash array.

-s

Remove escaping of the solidus symbol (stright slash).

-h

Show help text.

Format options

By default, parsed values are output in the form

[path]<tab>value

where path is the path for the value, <tab> is a literal tab, and value is the JSON value. That's nice and human-readable, but not always the best for parsing. These additional output formats are available. There are also short-forms available.

default (short: d)

This is the default output format that you get if -f isn't specified.

array (short: a)

This produces output suitable for loading directly into a bash associative array. It implies -n.

[path]=value

key-only (short: key)

Output just paths, one per line, without []'s. For example, run against package.json you get:

...
"bin","JSON.sh"
"bin"
...

key-value (short: kv)

Suitable for processing with the read built-in.

path<tab>value

value-only (short: value)

Similar to key mode, except you get values one-per-line instead.

Cool Links

Installation

install via npm or from AUR on archlinux

License

This software is available under the following licenses:

  • MIT
  • Apache 2

About

a pipeable JSON parser written in Bash

Resources

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE.APACHE2
MIT
LICENSE.MIT

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Shell 100.0%