{"id":13395436,"url":"https://github.com/davesnx/query-json","last_synced_at":"2025-04-12T14:17:55.768Z","repository":{"id":40555028,"uuid":"293107202","full_name":"davesnx/query-json","owner":"davesnx","description":"Faster, simpler and more portable implementation of `jq` in Reason","archived":false,"fork":false,"pushed_at":"2024-03-11T10:47:37.000Z","size":42780,"stargazers_count":592,"open_issues_count":3,"forks_count":6,"subscribers_count":11,"default_branch":"main","last_synced_at":"2025-04-12T14:17:27.977Z","etag":null,"topics":["json","menhir","ocaml","reason","reason-native","reasonml","sedlex"],"latest_commit_sha":null,"homepage":"https://query-json.netlify.app","language":"Reason","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/davesnx.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-09-05T15:54:41.000Z","updated_at":"2025-03-21T00:55:48.000Z","dependencies_parsed_at":"2024-09-29T06:51:04.136Z","dependency_job_id":null,"html_url":"https://github.com/davesnx/query-json","commit_stats":{"total_commits":267,"total_committers":3,"mean_commits":89.0,"dds":"0.014981273408239737","last_synced_commit":"c7cb3cef387ef39e07ce86098becdd379dde06fa"},"previous_names":[],"tags_count":136,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davesnx%2Fquery-json","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davesnx%2Fquery-json/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davesnx%2Fquery-json/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davesnx%2Fquery-json/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/davesnx","download_url":"https://codeload.github.com/davesnx/query-json/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248578876,"owners_count":21127714,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["json","menhir","ocaml","reason","reason-native","reasonml","sedlex"],"created_at":"2024-07-30T17:01:58.596Z","updated_at":"2025-04-12T14:17:55.745Z","avatar_url":"https://github.com/davesnx.png","language":"Reason","funding_links":[],"categories":["Reason","OCaml","\u003ca name='Repositories'\u003e\u003c/a\u003eRepositories"],"sub_categories":["\u003ca name='Clones'\u003e\u003c/a\u003eClones"],"readme":"\u003cp\u003e\n  \u003cbr\u003e\n  \u003cbr\u003e\n  \u003cimg width=\"250\" alt=\"query-json logo\" src=\"docs/dark-logo.svg#gh-light-mode-only\" /\u003e\n  \u003cimg width=\"250\" alt=\"query-json logo\" src=\"docs/white-logo.svg#gh-dark-mode-only\" /\u003e\n  \u003cbr\u003e\n  \u003cbr\u003e\n\u003c/p\u003e\n\n**query-json** is a [faster](#Performance), simpler and more portable implementation of the [jq language](https://github.com/stedolan/jq/wiki/jq-Language-Description) in [Reason](https://reasonml.github.io/docs/en/native) distributed as a dependency-free binary thanks to the OCaml compiler, and distributed to the web with [js_of_ocaml](https://github.com/ocsigen/js_of_ocaml).\n\n**query-json** allows you to write small programs to operate on top of json files with a concise syntax.\n\n[![asciicast](https://asciinema.org/a/b6g6ar2cQSAEAyn5qe7ptr98Q.svg)](https://asciinema.org/a/b6g6ar2cQSAEAyn5qe7ptr98Q)\n\n## Purpose\n\nIt was created with mostly two reasons, learning and having fun.\n\n- **Learn how to write a Programming Language with the OCaml stack** using `menhir` and `sedlex` with great error messages.\n- **Create a CLI tool in Reason Native** and being able to distribute it as a binary (for performance) and as a JavaScript library (for portability).\n\n## It brings\n\n- **Great Performance**: Fast, small footprint and minimum run-time. Check [Performance section](#Performance) for a longer explanation.\n- **Delightful errors**:\n  - Better errors when json types and operation don't match:\n    ```bash\n    $ query-json '.esy.release.wat' esy.json\n    Error:  Trying to \".wat\" on an object, that don't have the field \"wat\":\n    { \"bin\": ... }\n    ```\n  - `debug` prints the tokens and the AST.\n  - `verbose` flag, prints each operation in each state and it's intermediate states. _(Work in progress...)_\n- **Improved API**: made small adjustments to the buildin operations. Some examples are:\n  - All methods are snake_case instead of alltoghetercase\n  - Added `filter(p)` as an alias for `map(select(p))`\n  - Supports comments in JSONs\n- **Small**: Lexer, Parser and Compiler are just 300 LOC and most of the commands that I use on my day to day are implemented in only 140 LOC.\n\n## Installation\n\n### Using a bash script\n\nCheck the content of [scripts/install.sh](./scripts/install.sh) before running anything in your local. [Friends don't let friends curl | bash](https://sysdig.com/blog/friends-dont-let-friends-curl-bash).\n```bash\ncurl -sfL https://raw.githubusercontent.com/davesnx/query-json/master/scripts/install.sh | bash\n```\n\n### Using npm/yarn\n\n```bash\nnpm install --global @davesnx/query-json\n# or\nyarn global add @davesnx/query-json\n```\n\n### Download zip files from [GitHub](https://github.com/davesnx/query-json/releases)\n\n## Usage\n\nI recommend to write the query in single-quotes inside the terminal, since writting JSON requires double-quotes for accessing properties.\n\n\u003e NOTE: I have aliased query-json to be \"q\" for short, you can set it in your dotfiles. `alias q=\"query-json\"`.\n\n#### query a json file\n```bash\nq '.' pokemons.json\n```\n\n#### query from stdin\n```bash\ncat pokemons.json | q '.'\n```\n\n#### query a json inlined\n```bash\nq --kind=inline '.' '{ \"bulvasur\": { \"id\": 1, \"power\": 20 } }'\n```\n\n#### query without colors\n```bash\nq '.' pokemons.json --no-colors\n```\n\n## Performance\n\n[This report](./benchmarks/report.md) is not an exhaustive performance report of both tools, it's a overview for the percieved performance of the user. Here I don't profile each tool and try to see what are the bootlenecks, since I assume that both tools have the penalty of parsing a JSON file. Simply run a bash script and analyze the results.\n\nAside from that, **query-json** doesn't have feature parity with **jq** which is ok at this point, but **jq** contains a ton of functionality that query-json misses. Adding the missing operations on **query-json** won't affect the performance of it, that could not be true for features like \"modules\" or \"tests\", which they will not be implemented in **query-json**.\n\nThe report shows that **query-json** is between 2x and 5x faster than **jq** in all operations tested and same speed (~1.1x) with huge files (\u003e 100M).\n\n## Currently supported feature set:\n\n| Badge | Meaning             |\n| ----- | ------------------- |\n| ✅    | Implemented         |\n| ⚠️    | Not implemented yet |\n| 🔴    | Won't implement     |\n\n##### Based on jq 1.6\n\n#### [CLI: Invoking jq](https://stedolan.github.io/jq/manual/v1.6/#Invokingjq)\n  - `--version` ✅\n  - `--kind`. This is different than jq ✅\n    - `--kind=file` and the 2nd argument can be a json file\n    - `--kind=inline` and the 2nd argument can be a json as a string\n  - `--no-color`. This disables colors ✅\n  - ...rest ⚠️\n\n#### [Basic filters](https://stedolan.github.io/jq/manual/v1.6/#Basicfilters)\n  - Identity: `.` ✅\n  - Object Identifier-Index: `.foo`, `.foo.bar` ✅\n  - Optional Object Identifier-Index: `.foo?` ✅\n  - Generic Object Index: `.[\u003cstring\u003e]` ✅\n  - Array Index: `.[2]` ✅\n  - Pipe: `|` ✅\n  - Array/String Slice: `.[10:15]` ⚠️\n  - Array/Object Value Iterator: `.[]` ✅\n  - Comma: `,` ✅\n  - Parenthesis: `()` ✅️\n\n#### [Types and Values](https://stedolan.github.io/jq/manual/v1.6/#TypesandValues) ⚠️\n\n#### [Builtin operators and functions](https://stedolan.github.io/jq/manual/v1.6/#Builtinoperatorsandfunctions)\n\n  - Addition: `+` ✅\n  - Subtraction: `-` ✅\n  - Multiplication, division, modulo: `*`, `/`, and `%` ✅\n  - `length` ✅\n  - `keys` ✅\n  - `map` ✅\n  - `select` ✅\n  - `has(key)` ⚠️\n  - `in` ⚠️\n  - `path(path_expression)` ⚠️\n  - `to_entries`, `from_entries`, `with_entries` ⚠️\n  - `any`, `any(condition)`, `any(generator; condition)` ⚠️\n  - `all`, `all(condition)`, `all(generator; condition)` ⚠️\n  - `flatten` ✅\n  - `range(upto)`, `range(from;upto)` `range(from;upto;by)` ⚠️\n  - `floor`, `sqrt` ⚠️\n  - `tonumber`, `tostring` ⚠️\n  - `type` ⚠️\n  - `infinite`, `nan`, `isinfinite`, `isnan`, `isfinite`, `isnormal` ⚠️\n  - `sort`, `sort_by(path_expression)` ✅\n  - `group_by(path_expression)` ⚠️\n  - `min, max, min_by(path_exp), max_by(path_exp)` ⚠️\n  - `unique, unique_by(path_exp)` ⚠️\n  - `reverse` ⚠️\n  - `contains(element)` ⚠️\n  - `index(s), rindex(s)` ⚠️\n  - `startswith(str)`, `endswith(str)` ⚠️\n  - `explode`, `implode` ⚠️\n  - `split(str)`, `join(str)` ⚠️\n  - `while(cond; update)`, `until(cond; next)` ⚠️\n  - `recurse(f)`, `recurse`, `recurse(f; condition)`, `recurse_down` ⚠️\n  - `walk(f)` ⚠️\n  - `transpose(f)` ⚠️\n  - Format strings and escaping: `@text`, `@csv`, etc.. 🔴\n\n#### [Conditionals and Comparisons](https://stedolan.github.io/jq/manual/v1.6/#ConditionalsandComparisons)\n  - `==`, `!=` ✅\n  - `if-then-else` ⚠️\n  - `\u003e`, `\u003e=`, `\u003c=`, `\u003c` ✅\n  - `and`, `or`, `not` ⚠️\n  - `break` 🔴\n\n#### [Regular expressions (PCRE)](https://stedolan.github.io/jq/manual/v1.6/#RegularexpressionsPCRE) ⚠️\n\n#### [Advanced features](https://stedolan.github.io/jq/manual/v1.6/#Advancedfeatures) ⚠️\n\n#### [Assignment](https://stedolan.github.io/jq/manual/v1.6/#Assignment) ⚠️\n\n#### [Modules](https://stedolan.github.io/jq/manual/v1.6/#Modules) ⚠️\n\n## Contributing\n\nContributions are what make the open source community such an amazing place to be, learn, inspire, and create. Any contributions you make are greatly appreciated. If you have any questions just contact me [@twitter](https://twitter.com/davesnx) or email dsnxmoreno at gmail dot com.\n\n### Support\n\nI usually hang out at [discord.gg/reasonml](https://discord.com/channels/235176658175262720/235176658175262720) or [reasonml.chat](https://reasonml.chat) so feel free to ask anything there.\n\n### Setup\n\nRequirements: [esy](https://esy.sh)\n\n```bash\ngit clone https://github.com/davesnx/query-json\ncd query-json\nesy # installs\nesy test # runs unit tests with [rely](https://reason-native.com/docs/rely), live under test/.\nesy bin # Run binary\n```\n\n## Acknowledgements\n\nThanks to [@EduardoRFS](https://github.com/EduardoRFS). Thanks to all the authors of dependencies that this project relies on: [menhir](http://gallium.inria.fr/~fpottier/menhir), [sedlex](https://github.com/ocaml-community/sedlex), [yojson](https://github.com/ocaml-community/yojson). Thanks to the OCaml and Reason Native team.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavesnx%2Fquery-json","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdavesnx%2Fquery-json","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavesnx%2Fquery-json/lists"}