All Projects → TomConlin → json_to_paths

TomConlin / json_to_paths

Licence: other
Distill a JSON document into a collection of paths both for 'jq' and 'xpath'

Programming Languages

JSONiq
15 projects

Projects that are alternatives of or similar to json to paths

Aws
A collection of bash shell scripts for automating various tasks with Amazon Web Services using the AWS CLI and jq.
Stars: ✭ 493 (+658.46%)
Mutual labels:  jq
Oq
A performant, and portable jq wrapper to facilitate the consumption and output of formats other than JSON; using jq filters to transform the data.
Stars: ✭ 132 (+103.08%)
Mutual labels:  jq
Emuto
manipulate JSON files
Stars: ✭ 180 (+176.92%)
Mutual labels:  jq
Java Jq
Lightweight Java wrapper around JQ, a flexible JSON processor available for multiple platforms
Stars: ✭ 37 (-43.08%)
Mutual labels:  jq
Yq
Command-line YAML, XML, TOML processor - jq wrapper for YAML/XML/TOML documents
Stars: ✭ 1,688 (+2496.92%)
Mutual labels:  jq
Node Jq
Node.js wrapper for jq
Stars: ✭ 147 (+126.15%)
Mutual labels:  jq
Ticker.sh
Real-time stock tickers from the command-line.
Stars: ✭ 392 (+503.08%)
Mutual labels:  jq
jsqry-cli2
Small CLI tool (similar to jq) to query JSON using sane DSL
Stars: ✭ 21 (-67.69%)
Mutual labels:  jq
Jqr
R interface to jq
Stars: ✭ 123 (+89.23%)
Mutual labels:  jq
Jackson Jq
jq for Jackson Java JSON Processor
Stars: ✭ 178 (+173.85%)
Mutual labels:  jq
Jq Mode
Emacs major mode for editing jq queries.
Stars: ✭ 70 (+7.69%)
Mutual labels:  jq
Live Dl
Download live streams from YouTube
Stars: ✭ 82 (+26.15%)
Mutual labels:  jq
Json Splora
GUI for editing, visualizing, and manipulating JSON data
Stars: ✭ 1,818 (+2696.92%)
Mutual labels:  jq
Jqaas
jq as a service
Stars: ✭ 22 (-66.15%)
Mutual labels:  jq
Jq Web
jq in the browser with emscripten.
Stars: ✭ 188 (+189.23%)
Mutual labels:  jq
Jqplay
A playground for jq, written in Go
Stars: ✭ 444 (+583.08%)
Mutual labels:  jq
Pyjq
A Python binding for ./jq
Stars: ✭ 133 (+104.62%)
Mutual labels:  jq
ycat
Command line processor for YAML/JSON files using Jsonnet
Stars: ✭ 21 (-67.69%)
Mutual labels:  jq
jq-tutorial
Interactive exercises for learning jq
Stars: ✭ 109 (+67.69%)
Mutual labels:  jq
Tmux 1password
🔑 Access your 1Password login items within tmux!
Stars: ✭ 167 (+156.92%)
Mutual labels:  jq

JSON to jq paths or XML xpath

Purpose

To get insight into the structure of arbitrary JSON files from the command line. Provides building blocks for further processing both with 'jq' as well as other tools intended to be used with XML xpath.

Requirements

Usage

Snagging a random (to me) test JSON file from a neat looking awk json parser project

curl -sL https://github.com/step-/JSON.awk/raw/master/test-cases/20170131-issue-007-test.json > testdata.json

Result from generating jq paths

 ./json2jqpath.jq testdata.json > testdata.jqpath

Note: making up the format suffix .jqpath

cat testdata.jqpath
.
.response
.response|.count
.response|.data
.response|.data|.[]
.response|.data|.[]|.person
.response|.data|.[]|.person|.address
.response|.data|.[]|.person|.age
.response|.data|.[]|.person|.balance
.response|.data|.[]|.person|.company
.response|.data|.[]|.person|.coords
.response|.data|.[]|.person|.coords|.lat
.response|.data|.[]|.person|.coords|.long
.response|.data|.[]|.person|.email
.response|.data|.[]|.person|.gender
.response|.data|.[]|.person|.guid
.response|.data|.[]|.person|.id
.response|.data|.[]|.person|.isActive
.response|.data|.[]|.person|.name
.response|.data|.[]|.person|.phone
.response|.data|.[]|.person|.picture
.response|.data|.[]|.person|.registered
.response|.data|.[]|.person|.tags
.response|.data|.[]|.person|.tags|.[]
.response|.pagecount

This is a succinct representation of every simple path available through the json structure.

Example: To see what the distribution of most common tags in that file.

Noting that the path agrument to the next jq call
".response|.data|.[]|.person|.tags|.[]"
is cut-n-paste from the next to last line of output from json2jqpath.jq above.

jq ".response|.data|.[]|.person|.tags|.[]" testdata.json |
    sort | uniq -c | sort -nr | head
     75 "est"
     64 "labore"
     63 "consectetur"
     58 "occaecat"
     57 "fugiat"
     57 "excepteur"
     56 "proident"
     56 "Lorem"
     56 "laborum"
     56 "incididunt"

Looks like they used Lorem Ipsum as filler.

Try for something more specific such as person's name and location.

jq ".response|.data|.[]|.person|.name,.coords" testdata.json | head
"Anastasia Goodwin"
{
  "lat": 71.050828,
  "long": 113.565478
}
"Peters Watson"
{
  "lat": 0.203464,
  "long": -71.896296
}

Result for genreating XML xpaths

./json2xpath.jq testdata.json| sort -u > testdata.xpath
cat testdata.xpath
./response
./response/count
./response/data
./response/data/person
./response/data/person/address
./response/data/person/age
./response/data/person/balance
./response/data/person/company
./response/data/person/coords
./response/data/person/coords/lat
./response/data/person/coords/long
./response/data/person/email
./response/data/person/gender
./response/dfromata/person/guid
./response/data/person/id
./response/data/person/isActive
./response/data/person/name
./response/data/person/phone
./response/data/person/picture
./response/data/person/registered
./response/data/person/tags
./response/pagecount

which is a good starting point for tools such as xpath2dot.awk

./json2xpath.jq testdata.json |
    sort -u |
    xpath2dot.awk -v ORIENT="UD" |
    dot -T svg > testdata.svg

testdata.svg


A note on the use of sort -u above

The script json2xpath.jq has the ability to sort and remove duplicates but they are commented out.

They are disabled by default to allow more use cases for example:

  • We may be extracting data in some other program & want to know the native order
  • We may be interested in counts of things of various types

If you know these are not your use case you can uncomment them in the script and eliminate piping the output through sort -u

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].