Skip to content

Latest commit

 

History

History
135 lines (86 loc) · 2.43 KB

json.md

File metadata and controls

135 lines (86 loc) · 2.43 KB

JSON

JavaScript Object Notation.

For JSON basics, read Wikipedia.

Useful JSON tools:

gron

https://github.com/tomnomnom/gron

Flattens JSON to be greppable.

gron "https://api.github.com/repos/tomnomnom/gron/commits?per_page=1" |
fgrep "commit.author"

unflatten back to expanded JSON:

gron "https://api.github.com/repos/tomnomnom/gron/commits?per_page=1" |
fgrep "commit.author" |
gron -u

jq

JSON Query filters json inputs - file or stdin.

Pre-compiled C available for all platforms.

Widely used in my scripts in DevOps-Bash-tools repo.

https://jqlang.github.io/jq/tutorial/

https://jqlang.github.io/jq/manual/

jnv

https://github.com/ynqa/jnv

Interactive JSON viewer.

Useful to quickly create jq queries by drilling down interactively.

cat data.json | jnv

or

jnv data.json

Tab completion.

Ctrl-q - copy jq query to clipboard to paste to code.

Ctrl-o - copy the JSON to clipboard.

More Keyboard shortcuts.

Java Libraries

  • Jackson
  • Gson

Conversion

XML to JSON

xml2json

JSON to CSV

json2csv

Pretty Print / format JSON

Perl JSON::XS CPAN module (doesn't sort keys):

json_xs

Python 2.6+ (sorts keys):

python -m json.tool

JSON Linting

From DevOps-Bash-tools, recursively find and lint all *.json files:

check_json.sh

From DevOps-Python-tools, recursively find and lint all *.json files:

validate_json.py .

I run these automatically in all my GitHub repos via CI/CD.

IDEs

  • Eclipse JSONTools validation plugin (Help -> MarketPlace)
    • needs file extensions to be .json (not .template from AWS CloudFormation)
  • IntelliJ also has JSON error validation but it's not as easy to see underscores vs the big red cross Eclipse puts in the left column