All Projects → yamafaktory → Jql

yamafaktory / Jql

Licence: mit
A JSON Query Language CLI tool

Programming Languages

rust
11053 projects

Projects that are alternatives of or similar to Jql

Dasel
Query, update and convert data structures from the command line. Comparable to jq/yq but supports JSON, TOML, YAML, XML and CSV with zero runtime dependencies.
Stars: ✭ 759 (+106.25%)
Mutual labels:  cli, json, devops-tools
Visidata
A terminal spreadsheet multitool for discovering and arranging data
Stars: ✭ 4,606 (+1151.63%)
Mutual labels:  cli, json, devops-tools
Jtc
JSON processing utility
Stars: ✭ 425 (+15.49%)
Mutual labels:  cli, json, tool
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 (-64.13%)
Mutual labels:  cli, json, devops-tools
Remarshal
Convert between CBOR, JSON, MessagePack, TOML, and YAML
Stars: ✭ 421 (+14.4%)
Mutual labels:  utility, cli, json
Laravel Zero
A PHP framework for console artisans
Stars: ✭ 2,821 (+666.58%)
Mutual labels:  utility, cli, tool
Fselect
Find files with SQL-like queries
Stars: ✭ 3,103 (+743.21%)
Mutual labels:  utility, cli, tool
Musoq
Use SQL on various data sources
Stars: ✭ 252 (-31.52%)
Mutual labels:  utility, cli, tool
Jaggr
JSON Aggregation CLI
Stars: ✭ 365 (-0.82%)
Mutual labels:  cli, json
Rawkit
🦊 Immediately Open Chrome DevTools when debugging Node.js apps
Stars: ✭ 306 (-16.85%)
Mutual labels:  cli, tools
Xxl Tool
a series of tools that make Java development more efficient.(Java工具类库XXL-TOOL)
Stars: ✭ 311 (-15.49%)
Mutual labels:  json, tool
Frankenstein
Correct README Redirects
Stars: ✭ 305 (-17.12%)
Mutual labels:  cli, tool
Gkill
Interactice process killer for Linux and macOS
Stars: ✭ 297 (-19.29%)
Mutual labels:  cli, tools
Pastel
A command-line tool to generate, analyze, convert and manipulate colors
Stars: ✭ 3,742 (+916.85%)
Mutual labels:  cli, tool
Circleci Cli
Use CircleCI from the command line
Stars: ✭ 297 (-19.29%)
Mutual labels:  cli, tool
Fd
A simple, fast and user-friendly alternative to 'find'
Stars: ✭ 19,851 (+5294.29%)
Mutual labels:  cli, tool
Utils Everywhere
整理并收集各种常用的覆盖面广的工具类
Stars: ✭ 329 (-10.6%)
Mutual labels:  tool, tools
Ghb0t
A GitHub Bot to automatically delete your fork's branches after a pull request has been merged.
Stars: ✭ 295 (-19.84%)
Mutual labels:  cli, tools
Haxor News
Browse Hacker News like a haxor: A Hacker News command line interface (CLI).
Stars: ✭ 3,342 (+808.15%)
Mutual labels:  utility, cli
Jet
CLI to transform between JSON, EDN and Transit, powered with a minimal query language.
Stars: ✭ 331 (-10.05%)
Mutual labels:  cli, json

JQL Build Status

A JSON Query Language CLI tool built with Rust 🦀

📜 Core philosophy

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

🚀 Installation

Cargo

cargo install jql

Archlinux

The AUR package is maintained by @frol.

yay -S jql

🛠️ Usage

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

Root selection

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

Child selection

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

Index selection

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

Please note that the following is also valid:

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

You can also select a set of indexes:

jql '"primes".[2,0]' example.json
[
  13,
  7
]

Range selection

{
  "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"

You can also use the start or the end position as a range selector:

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

Array selection

{
  "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

Property selection

{
  "object": { "a": 1, "b": 2, "c": 3 }
}
jql '"object".{"a","c"}' example.json
{
  "a": 1,
  "c": 3
}

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
[
  [
    "Asus",
    "Apple"
  ],
  [
    "Apple",
    "Asus"
  ]
]

Flatten arrays

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

Truncate

The truncate selector ! can be used to stop walking the children's values and to explore an unknown JSON file / structure. Each children is then transformed into a JSON primitive for convenience, e.g.:

primitive value result
object { "a": 1, "b": 2, "c": 3 } {}
array [1, 2, 3] []
string "foo" "foo"
number 666 666
null null null
{
  "foo": {
    "a": null,
    "b": "bar",
    "c": 1337,
    "d": {
      "woot": [
        1,
        2,
        3
      ]
    }
  }
}
jql '.!' example.json
{
  "foo": {}
}
jql '"foo"!' example.json
{
  "a": null,
  "b": "bar",
  "c": 1337,
  "d": {}
}

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

Raw output

Use the raw-output flag on a string selection to directly return the raw string without JSON double-quotes:

echo "{\"foo\":\"bar\"}" | jql --raw-output '"foo"'
bar
echo "{\"foo\":\"bar\"}" | jql -r '"foo"'
bar

Streaming

Use the stream flag to read a stream of JSON lines:

while true; do echo '{"foo": 2}'; sleep 1; done | cargo run '.!' --stream
while true; do echo '{"foo": 2}'; sleep 1; done | cargo run '.!' -s

Please note that this option is only about reading valid JSON output streamed line by line (e.g. Docker logs with the --follow flag). This is not an option to read an incomplete streamed content (e.g. a very large input)!

🍿 Library

This crate is both a binary (the CLI tool) and a library that can be directly used https://docs.rs/crate/jql/.

⚡ Performance

Some benchmarks comparing a set of similar functionalities provided by this tool and jq are available here.

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].