Skip to content
Command-line JSON processor with Scala syntax
Branch: master
Clone or download
Latest commit 181840d Jul 5, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
project Add tests and fix not working stuff Jul 5, 2019
src fix one test Jul 5, 2019
.gitignore first commit Jul 4, 2019
.scalafmt.conf first commit Jul 4, 2019
.travis.yml Add travis support Jul 5, 2019
README.md Update README.md Jul 5, 2019
build.sbt Add tests and fix not working stuff Jul 5, 2019
version.sbt Move version Jul 5, 2019

README.md

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.

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

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

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
You can’t perform that action at this time.