JQR is command line tool for exploring JSON documents, heavily inspired by jq, but written in Rust. It's very much work in progress!
Easiest way to use jqr is to install it as a Rust binary on your OS path, which can be done very easily with cargo install
. For this and all following steps you'll need rust tools installed, please follow steps detailed on official install Rust page.
cd jqr
cargo install --path .
jqr sample-github.json "[0] | {parents} | [0] | { html_url }"
jqr 004ff2c5-7ed0-433b-8638-e6ceeceb1d09-7 "Records | [0] | { firstDate = FirstDate; data= Details | [0,2,23] | {clk = Clicks;dt = Date;AdType = Grouping.AdTypeId} }"
No argument just pretty prints json contents
jqr test1.json
[
{
"models": [
"Fiesta",
"Focus",
"Mustang"
],
"name": "Ford"
},
{
"models": [
"320",
"X3",
"X5"
],
"name": "BMW"
},
{
"models": [
"500",
"Panda"
],
"name": "Fiat"
}
]
ToDo - neex fixing, currently it's aways parsed as MultiCmd and only first index is returned
jqr test1.json "[0,2]"
{
"models": [
"Fiesta",
"Focus",
"Mustang"
],
"name": "Ford"
}
mixing array based and keyword access to slice and dice complex json documents
This document is borrowed from JQ tutorial and can be access like below
curl 'https://api.github.com/repos/stedolan/jq/commits?per_page=5' > sample-github.com
jqr sample-github.json "[0] | {author}"
{
"avatar_url": "https://avatars2.githubusercontent.com/u/375258?v=4",
"events_url": "https://api.github.com/users/itchyny/events{/privacy}",
"followers_url": "https://api.github.com/users/itchyny/followers",
"following_url": "https://api.github.com/users/itchyny/following{/other_user}",
"gists_url": "https://api.github.com/users/itchyny/gists{/gist_id}",
"gravatar_id": "",
"html_url": "https://github.com/itchyny",
"id": 375258,
"login": "itchyny",
"node_id": "MDQ6VXNlcjM3NTI1OA==",
"organizations_url": "https://api.github.com/users/itchyny/orgs",
"received_events_url": "https://api.github.com/users/itchyny/received_events",
"repos_url": "https://api.github.com/users/itchyny/repos",
"site_admin": false,
"starred_url": "https://api.github.com/users/itchyny/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/itchyny/subscriptions",
"type": "User",
"url": "https://api.github.com/users/itchyny"
}
jqr sample-github.json "[0] | committer | .vals"
[
"avatar_url",
"events_url",
"followers_url",
"following_url",
"gists_url",
"gravatar_id",
"html_url",
"id",
"login",
"node_id",
"organizations_url",
"received_events_url",
"repos_url",
"site_admin",
"starred_url",
"subscriptions_url",
"type",
"url"
]
jqr sample-github.json "[0] | committer | .vals"
[
"avatar_url",
"events_url",
"followers_url",
"following_url",
"gists_url",
"gravatar_id",
"html_url",
"id",
"login",
"node_id",
"organizations_url",
"received_events_url",
"repos_url",
"site_admin",
"starred_url",
"subscriptions_url",
"type",
"url"
]
jqr --release sample-github.json "[0] | { parents } | [0] | {url}"
Cmd=MultiCmd([MultiArrayIndex([0]), KeywordAccess(["parents"]), MultiArrayIndex([0]), KeywordAccess(["url"])])
"https://api.github.com/repos/stedolan/jq/commits/9163e09605383a88f6e953d6cb5cc2aebe18c84f"
jqr sample-github.json "[0] | { commit.author } "
{
"date": "2020-05-09T01:39:38Z",
"email": "itchyny@hatena.ne.jp",
"name": "itchyny"
}
jqr sample-github.json "[0] | author | .keys"
jqr sample-github.json "[0] | { myEventName = author.events_url; author = commit.author.name}"
{
"author": "itchyny",
"myEventName": "https://api.github.com/users/itchyny/events{/privacy}"
}
- get parent url
```bash
jqr sample-github.json "[0] | { parentUrl = parents | [0] | url } "
- get first parent url, parent sha and child sha
jqr sample-github.json "[0] | { parentUrl = parents | [0] | url; parentSha = parents | [0] | sha; childSha = sha}"
{
"childSha": "6306ac89667cf35f47ddc40aa0630546c57e387f",
"parentSha": "9163e09605383a88f6e953d6cb5cc2aebe18c84f",
"parentUrl": "https://api.github.com/repos/stedolan/jq/commits/9163e09605383a88f6e953d6cb5cc2aebe18c84f"
}
jqr sample-github.json "[0] | { parentSha = parents | [0] | sha; sha = sha }"
{
"parentSha": "9163e09605383a88f6e953d6cb5cc2aebe18c84f",
"sha": "6306ac89667cf35f47ddc40aa0630546c57e387f"
}
jqr sample-github.json "[0] | { parentUrl = parents | [0] } | parentUrl.url"
cat large-json-lines-file.json | head -n 1 | jqr "[3] | { committer } "