https://github.com/yannick-cw/sjq
Command-line JSON processor with Scala syntax
https://github.com/yannick-cw/sjq
cli command-line jq json scala
Last synced: 5 months ago
JSON representation
Command-line JSON processor with Scala syntax
- Host: GitHub
- URL: https://github.com/yannick-cw/sjq
- Owner: yannick-cw
- Created: 2019-07-04T14:44:49.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2024-07-11T02:48:51.000Z (about 1 year ago)
- Last Synced: 2025-04-03T03:02:21.328Z (6 months ago)
- Topics: cli, command-line, jq, json, scala
- Language: Scala
- Size: 35.2 KB
- Stars: 53
- Watchers: 2
- Forks: 2
- Open Issues: 40
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# sjq
## About
Use Scala syntax to modify json fast and however you want from the Commandline.
Just pass `code` to modify the `root` case class. sjq parses the json to a case class and allows editing and modifying it in any way.
e.g.
```bash
sjq -a 'root.subclass.copy(name = root.subclass.name + "Jo")' -j '{ "subclass": { "name": "Ho", "ids": [22, 23, 24] }}'
{
"name" : "HoJo",
"ids" : [
22.0,
23.0,
24.0
]
}
```One example with a more complex json and a remote api:
##### Get all hotel names with a score over 300
```
curl https://www.holidaycheck.de/svc/search-api/search/mall\?tenant\=test \
| sjq -a 'root.destinations.entities.filter(_.rankingScore > 300).map(_.name)'
```returns
```
[
"Mallorca",
"Malles Venosta / Mals",
"Palma de Mallorca"
]
```## Install
`brew install yannick-cw/homebrew-tap/sjq`
Or download the executable from the releases.
## Usage
You can pass any valid scala code to access the json, the json is internally represented as a case class.
The input to use is the case class `root`
```bash
sjq -a 'root.subclass.ids.filter(id => id > 22)' -j '{ "subclass": { "name": "Ho", "ids": [22, 23, 24] }}'
## Results in
[
23.0,
24.0
]
```### Alternatively pipe input
```bash
echo '{ "subclass": { "name": "Ho", "ids": [22, 23, 24] }}' | sjq -a 'root.subclass.ids.filter(id => id > 22)'
```## Planned features
* support subclasses with the same name with different value types
* interactive mode with auto complete on json