jql 1.0.1

A JSON query language CLI tool
jql-1.0.1 is not a library.
Visit the last successful build: jql-5.2.0

JQL

A JSON Query Language CLI tool

The core philosophy of jql:

  • Keep its features as simple as possible
  • Avoid redunduncy
  • 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 example.json '"some"."property"'
"yay!"

Accessing an index

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

Please note that the following is also valid:

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

Accessing a range

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

Please note that you can reverse it:

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

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

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

Please note that you can still access the children:

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

Multi-selection

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

Filter

{
  "laptops": [
    {
      "laptop": {
        "brand": "Apple",
        "options": ["a", "b", "c"]
      }
    },
    {
      "laptop": {
        "brand": "Asus",
        "options": ["d", "e", "f"]
      }
    }
  ]
}
jql example.json '"laptops"|"laptop"'
[
  {
    "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 example.json '"laptops"|"laptop"."brand"'
[
  "Apple",
  "Asus"
]
jql example.json '"laptops".[1:0]|"laptop"."brand","laptops"|"laptop"."brand"'
[
  [
    "Asus",
    "Apple"
  ],
  [
    "Apple",
    "Asus"
  ]
]

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

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

Flattening arrays

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

Special characters

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

How to save the output

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

Available flags 🤖

Help

jql -h
jql --help

Version

jql -V
jql --version

Inlining the JSON output

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