A JSON Query Language CLI tool
Switch branches/tags
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src Add multiline stdin support. Dec 12, 2018
.gitignore Cargo.lock should be tracked! Dec 12, 2018
.travis.yml Extend TravisCI yaml file 🤞. Dec 12, 2018
Cargo.lock Bump up version ⬆️. Dec 12, 2018
Cargo.toml Bump up version ⬆️. Dec 12, 2018
README.md Update readme. Dec 12, 2018
rustfmt.toml 🐼 Sep 2, 2018

README.md

JQL

A JSON Query Language CLI tool

📜 Core philosophy of jql:

  • 🎮 Keep its features as simple as possible
  • 🧠 Avoid redundancy
  • 💡 Provide meaningful error messages
  • ↔️ Eat JSON as input, process, output JSON back

🚀 Installation

cargo install jql

🛠️ Usage

If you find some of the following examples confusing, please have a look at The JavaScript Object Notation (JSON) Data Interchange Format.

Accessing the root

"This is a valid JSON text with one value"
jql '.' example.json
"This is a valid JSON text with one value"

Accessing a child

{
  "some": {
    "property": "yay!"
  }
}
jql '"some"."property"' example.json
"yay!"

Accessing an index

{
  "primes": [7, 11, 13]
}
jql '"primes".[0]' example.json
7

Please note that the following is also valid:

jql '"primes"[0]"' example.json
7

Accessing a range

{
  "cats": [{ "first": "Pixie" }, { "second": "Kitkat" }, { "third": "Misty" }]
}
jql '"cats".[1:2]' example.json
[
  {
    "second": "Kitkat"
  },
  {
    "third": "Misty"
  }
]

Please note that you can reverse it:

jql '"cats".[2:1]' example.json
[
  {
    "third": "Misty"
  },
  {
    "second": "Kitkat"
  }
]

Bonus, you can do it again to get it back:

jql '"cats".[2:1].[1:0]' example.json
[
  {
    "second": "Kitkat"
  },
  {
    "third": "Misty"
  }
]

Please note that you can still access the children:

jql '"cats".[2:1].[0]."third"' example.json
"Misty"

Accessing an array

{
  "primes": [7, 11, 13]
}
jql '"primes".[]' example.json
[
  7,
  11,
  13
]

Please note that this is basically an alias for a full range selection:

jql '"primes".[0:2]' example.json

Multi-selection

{
  "one": [1, 2, 3],
  "two": 2,
  "three": 3
}
jql '"one".[2:0],"two","three"' example.json
[
  [
    3,
    2,
    1
  ],
  2,
  3
]

Filter

{
  "laptops": [
    {
      "laptop": {
        "brand": "Apple",
        "options": ["a", "b", "c"]
      }
    },
    {
      "laptop": {
        "brand": "Asus",
        "options": ["d", "e", "f"]
      }
    }
  ]
}
jql '"laptops"|"laptop"' example.json
[
  {
    "brand": "Apple",
    "options": ["a", "b", "c"]
  },
  {
    "brand": "Asus",
    "options": ["d", "e", "f"]
  }
]

You can also combine a filter with a child selection, a multi-selection and ranges at the same time:

jql '"laptops"|"laptop"."brand"' example.json
[
  "Apple",
  "Asus"
]
jql '"laptops".[1:0]|"laptop"."brand","laptops"|"laptop"."brand"' example.json
[
  [
    "Asus",
    "Apple"
  ],
  [
    "Apple",
    "Asus"
  ]
]

Please note that you can combine filters to achieve the same result:

jql '"laptops".[1:0]|"laptop"|"brand","laptops"|"laptop"|"brand"' example.json
[
  "Apple",
  "Asus"
]

Flattening arrays

{
  "dna": [[[[["c", "a", "c"]]]], "g", "t", [[["a", ["t"]]]]]
}
jql '.."dna"' example.json
[
  "c",
  "a",
  "c",
  "g",
  "t",
  "a",
  "t"
]

Special characters

{
  ".valid": 1337,
  "": "yeah!",
  "\"": "yup, valid too!"
}
jql '".valid"' example.json
1337
jql '""' example.json
"yeah!"
jql '"\""' example.json
"yup, valid too!"

💻 Shell integration

How to save the output

jql '"foo"."bar"' input.json > output.json

How to read from stdin

cat example.json | jql '"foo"."bar"'

Available flags 🤖

Help

jql -h
jql --help

Version

jql -V
jql --version

Inlining the JSON output

jql -i 'some.selector' example.json
jql --inline 'some.selector' example.json