{"id":15502631,"url":"https://github.com/vaclavsvejcar/sjq","last_synced_at":"2025-04-22T23:14:54.420Z","repository":{"id":134659641,"uuid":"256978342","full_name":"vaclavsvejcar/sjq","owner":"vaclavsvejcar","description":"⚗️Command-line JSON processor with embedded Ammonite REPL","archived":false,"fork":false,"pushed_at":"2022-03-30T07:03:10.000Z","size":122,"stargazers_count":8,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-22T23:14:47.016Z","etag":null,"topics":["ammonite-repl","json","scala"],"latest_commit_sha":null,"homepage":"","language":"Scala","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/vaclavsvejcar.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-04-19T11:07:28.000Z","updated_at":"2023-04-28T13:41:11.000Z","dependencies_parsed_at":"2023-07-18T03:46:00.576Z","dependency_job_id":null,"html_url":"https://github.com/vaclavsvejcar/sjq","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vaclavsvejcar%2Fsjq","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vaclavsvejcar%2Fsjq/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vaclavsvejcar%2Fsjq/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vaclavsvejcar%2Fsjq/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vaclavsvejcar","download_url":"https://codeload.github.com/vaclavsvejcar/sjq/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250337950,"owners_count":21414104,"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":["ammonite-repl","json","scala"],"created_at":"2024-10-02T09:10:32.190Z","updated_at":"2025-04-22T23:14:54.407Z","avatar_url":"https://github.com/vaclavsvejcar.png","language":"Scala","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\u003cimg src =\"https://github.com/vaclavsvejcar/sjq/raw/master/doc/assets/logo.png\" width=\"200\" /\u003e\u003c/p\u003e\n\nYou may know the [jq JSON command line processor][web:jq]. You may also know the [ammonite REPL][web:ammonite-repl]. Now imagine that you combine these two awesome tools into single one and you have the __sjq__.\n\n__sjq__ is a small tool written in [Scala][web:scala] that compiles your input _JSON_ into _Scala case classes_, so you can use __Scala expressions__ and collections API __to transform your data__, no need to remember any special syntax! And thanks to the embedded [ammonite REPL][web:ammonite-repl], you can use all that goodies such as __syntax highlighting__, __auto completion on TAB__ and much more! Manipulating _JSON_ data has never been easier :-)\n\n\u003e 🚧 __Work in Progress__ 🚧 - This software is under active development and hasn't even reached its initial public release. Please bear in mind that documentation is likely missing and API and/or command line interface can change unexpectedly. At least for now, below is small demo how you can use __sjq__ right now.\n\n## 1. Example of Use\n[![asciicast](https://asciinema.org/a/xRAifzwiJ961vYO6wpoq78Z3s.svg)](https://asciinema.org/a/xRAifzwiJ961vYO6wpoq78Z3s)\n## 2. Table of Contents\n\u003c!-- TOC --\u003e\n\n- [1. Example of Use](#1-example-of-use)\n- [2. Table of Contents](#2-table-of-contents)\n- [3. Installation](#3-installation)\n    - [3.1. From Source Code](#31-from-source-code)\n- [4. Usage](#4-usage)\n    - [4.1. Interactive (REPL) Mode](#41-interactive-repl-mode)\n        - [4.1.1. Example](#411-example)\n        - [4.1.2. Command Line Options](#412-command-line-options)\n        - [4.1.3. Exposed variables](#413-exposed-variables)\n    - [4.2. Non-interactive (CLI) Mode](#42-non-interactive-cli-mode)\n        - [4.2.1. Example](#421-example)\n        - [4.2.2. Command Line Options](#422-command-line-options)\n- [5. How it Works?](#5-how-it-works)\n- [6. Known Issues / Future Work](#6-known-issues--future-work)\n\n\u003c!-- /TOC --\u003e\n\n## 3. Installation\n\n\u003e Pre-built _JAR_ files and binary distribution coming soon!\n\n### 3.1. From Source Code\nTo build __sjq__ from source code, you need to install [sbt][web:sbt] first.\n\n```sh\n$ git clone https://github.com/vaclavsvejcar/sjq.git\n$ cd sjq/\n$ sbt assembly\n```\n\nThen grab the built _JAR_ file from `./target/scala-2.13/sjq-assembly-\u003cVERSION\u003e.jar` and you're ready to go!\n\n## 4. Usage\n__sjq__ offers two different modes, the __Interactive (REPL) Mode__ which uses the [ammonite REPL][web:ammonite-repl] for interactive work, and __Non-interactive (CLI) Mode__ which is useful when you need to call __sjq__ from another shell script, etc.\n\n### 4.1. Interactive (REPL) Mode\nProbably the biggest advantage over similar tools is the interactive mode, powered by the awesome [ammonite REPL][web:ammonite-repl]. In this mode, __sjq__ takes your input JSON, compiles it into Scala code and then exposes them through the _ammonite REPL_. Then you can work with your data as with regular Scala code, with all the goodies such as __syntax highlighting__ and __auto completion on TAB__:\n\n#### 4.1.1. Example\n\n```sh\n\n$ java -jar sjq.jar repl -f path/to/file.json\n\n--- Welcome to sjq REPL mode ---\nCompiling type definitions from input JSON (this may take a while)...\n\n\n[i] Variable 'root' holds Scala representation of parsed JSON\n[i] Variable 'json' holds parsed JSON\n[i] Variable 'ast' holds internal AST representation of data (for debugging purposes)\n[i] Variable 'defs' holds generated Scala definitions (for debugging purposes)\n[i] To serialize data back to JSON use '.asJson.spaces2'\n\n\nWelcome to the Ammonite Repl 2.1.1 (Scala 2.13.2 Java 1.8.0_222)\n@ root.users \nres0: Seq[root0.users] = List(users(\"John Smith\", 42.0), users(\"Peter Taylor\", 67.0), users(\"Lucy Snow\", 21.0))\n\n@ root.users.sortBy(_.age) \nres1: Seq[root0.users] = List(users(\"Lucy Snow\", 21.0), users(\"John Smith\", 42.0), users(\"Peter Taylor\", 67.0))\n```\n\n#### 4.1.2. Command Line Options\nInteractive mode is executed using the `java -jar sjq.jar repl` and you need to specify the source of input JSON either as local file (`-f|--file=PATH`) or as inline value (`-j|--json=JSON`).\n\n#### 4.1.3. Exposed variables\nFollowing variables are exposed to the _ammonite REPL_, so you can access them as needed:\n\n- `root` - _Scala_ representation of _JSON_ data, this is probably what you'll use the most\n- `json` - [Circe's][web:circe] representation of parsed _JSON_ data\n- `ast` - __sjq__'s internal representation of parsed _JSON_ data\n- `defs` - _Scala_ definitions and types generated from the _JSON_ data\n\n### 4.2. Non-interactive (CLI) Mode\nIf you don't want to use the interactive mode, then this mode is here for you. It might be useful for example for some _shell script_, when it can perform JSON transformations as part of some larger task.\n\n#### 4.2.1. Example\n```sh\n$ cat /tmp/example.json | java -jar sjq.jar cli -a \"root.users.sortBy(_.age).asJson.noSpaces\"                                                                    \n\"[{\\\"name\\\":\\\"Lucy Snow\\\",\\\"age\\\":21.0},{\\\"name\\\":\\\"John Smith\\\",\\\"age\\\":42.0},{\\\"name\\\":\\\"Peter Taylor\\\",\\\"age\\\":67.0}]\"\n```\n\n#### 4.2.2. Command Line Options\nNon-interactive mode is executed using the `java -jar sjq.jar cli`. You need to specify the transformation code as `-a|--access=CODE` argument and input JSON as either _STDIN_ or as `-j|--json=JSON` argument.\n\n\n## 5. How it Works?\nFor the curious ones, here's how __sjq__ works under the hood:\n\n1. First step is to parse internal _AST_ representation from the input _JSON_ (see [dev.svejcar.sjq.core.Parser][meta:file/Parser]).\n1. Next step is to emit valid _Scala_ code (_case classes_ and _objects_) matching the input _JSON_ (see [dev.svejcar.sjq.core.Emitter][meta:file/Emitter]). This code is the compiled in runtime (this is the part that may take long time).\n1. Last step is to read the input JSON data into generated _Scala_ representation. This is done using the [Circe's automatic derivation][web:circe/auto-derivation] mechanism.\n\n## 6. Known Issues / Future Work\n__sjq__ is under heavy development and things might not be perfect yet. Here is the list of known issues and/or limitations that should be targeted in future releases:\n\n- __Performance:__ compile more complex __JSON__ can be __very slow__, as it needs to do both __compilation in runtime__ of generated _Scala_ code and __generic derivation__ for _Circe's decoders/encoders_. Performance improvements should be one of main targets in future releases\n- __Occasional crashes:__ more complex __JSON__ structures might cause runtime crashes, mostly due to incorrectly generated _Scala_ code and/or not matching derived _JSON_ encoders/decoders. If that happens for you, please [report that as new issue][meta:issues].\n\n\n[meta:file/Emitter]: https://github.com/vaclavsvejcar/sjq/blob/master/src/main/scala/dev/svejcar/sjq/core/Emitter.scala\n[meta:file/Parser]: https://github.com/vaclavsvejcar/sjq/blob/master/src/main/scala/dev/svejcar/sjq/core/Parser.scala\n[meta:file/Sanitizer]: https://github.com/vaclavsvejcar/sjq/blob/master/src/main/scala/dev/svejcar/sjq/core/Sanitizer.scala\n[meta:issues]: https://github.com/vaclavsvejcar/sjq/issues\n[web:ammonite-repl]: https://ammonite.io/#Ammonite-REPL\n[web:circe]: https://circe.github.io/\n[web:circe/auto-derivation]: https://circe.github.io/circe/codecs/auto-derivation.html\n[web:jq]: https://stedolan.github.io/jq/\n[web:sbt]: https://www.scala-sbt.org/\n[web:scala]: https://www.scala-lang.org\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvaclavsvejcar%2Fsjq","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvaclavsvejcar%2Fsjq","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvaclavsvejcar%2Fsjq/lists"}