All Projects → schibsted → Jslt

schibsted / Jslt

Licence: apache-2.0
JSON query and transformation language

Programming Languages

java
68154 projects - #9 most used programming language
language
365 projects

Projects that are alternatives of or similar to Jslt

Omniparser
omniparser: a native Golang ETL streaming parser and transform library for CSV, JSON, XML, EDI, text, etc.
Stars: ✭ 148 (-59.67%)
Mutual labels:  json, transform
Stubbornjava
Unconventional Java code for building web servers / services without a framework. Think dropwizard but as a seed project instead of a framework. If this project had a theme it would be break the rules but be mindful of your decisions.
Stars: ✭ 184 (-49.86%)
Mutual labels:  json, jackson
Jackson Core
Core part of Jackson that defines Streaming API as well as basic shared abstractions
Stars: ✭ 2,003 (+445.78%)
Mutual labels:  json, jackson
Kripton
A Java/Kotlin library for Android platform, to manage bean's persistence in SQLite, SharedPreferences, JSON, XML, Properties, Yaml, CBOR.
Stars: ✭ 110 (-70.03%)
Mutual labels:  json, jackson
Jackson Databind
General data-binding package for Jackson (2.x): works on streaming API (core) implementation(s)
Stars: ✭ 2,959 (+706.27%)
Mutual labels:  json, jackson
Gwt Jackson
gwt-jackson is a JSON parser for GWT. It uses Jackson 2.x annotations to customize the serialization/deserialization process.
Stars: ✭ 110 (-70.03%)
Mutual labels:  json, jackson
Jackson Jq
jq for Jackson Java JSON Processor
Stars: ✭ 178 (-51.5%)
Mutual labels:  json, jackson
Rumble
⛈️ Rumble 1.11.0 "Banyan Tree"🌳 for Apache Spark | Run queries on your large-scale, messy JSON-like data (JSON, text, CSV, Parquet, ROOT, AVRO, SVM...) | No install required (just a jar to download) | Declarative Machine Learning and more
Stars: ✭ 58 (-84.2%)
Mutual labels:  json, query
fastener
Functional Zipper for manipulating JSON
Stars: ✭ 54 (-85.29%)
Mutual labels:  query, transform
Bson4jackson
A pluggable BSON generator and parser for the Jackson JSON processor.
Stars: ✭ 244 (-33.51%)
Mutual labels:  json, jackson
Emfjson Jackson
JSON Binding for Eclipse Modeling Framework
Stars: ✭ 79 (-78.47%)
Mutual labels:  json, jackson
Jsonista
Clojure library for fast JSON encoding and decoding.
Stars: ✭ 290 (-20.98%)
Mutual labels:  json, jackson
Ducky
Duck-Typed Value Handling for JavaScript
Stars: ✭ 71 (-80.65%)
Mutual labels:  json, query
Gojsonq
A simple Go package to Query over JSON/YAML/XML/CSV Data
Stars: ✭ 1,790 (+387.74%)
Mutual labels:  json, query
Js Jsonq
A simple Javascript Library to Query over Json Data
Stars: ✭ 67 (-81.74%)
Mutual labels:  json, query
Jackson Datatype Money
Extension module to properly support datatypes of javax.money
Stars: ✭ 165 (-55.04%)
Mutual labels:  json, jackson
Jsonj
A fluent Java API for manipulating json data structures
Stars: ✭ 42 (-88.56%)
Mutual labels:  json, jackson
Easyjson
Provides an unified JSON access API, you can adapter any JSON library to Gson, Jackson, FastJson with easyjson。 提供了一个JSON门面库,就像slf4j一样。easyjson本身不做json的操作,完全依赖于底层实现库。可以直接使用Easyjson的API,底层的JSON库随时可切换。也可以使用其中某个json的API,然后通过easyjson适配给其他的json库
Stars: ✭ 54 (-85.29%)
Mutual labels:  json, jackson
Octosql
OctoSQL is a query tool that allows you to join, analyse and transform data from multiple databases and file formats using SQL.
Stars: ✭ 2,579 (+602.72%)
Mutual labels:  json, query
Json Schema Validator
A fast Java JSON schema validator that supports draft V4, V6, V7 and V2019-09
Stars: ✭ 292 (-20.44%)
Mutual labels:  json, jackson

JSLT

JSLT is a complete query and transformation language for JSON. The language design is inspired by jq, XPath, and XQuery.

JSLT can be used as:

  • a query language to extract values from JSON (.foo.bar[0]),
  • a filter/check language to test JSON objects (starts-with(.foo.bar[0], "http://")) ,
  • a transformation language to convert between JSON formats.

Here is an example transform:

{
    "time": round(parse-time(.published, "yyyy-MM-dd'T'HH:mm:ssX") * 1000),
    "device_manufacturer": .device.manufacturer,
    "device_model": .device.model,
    "language": .device.acceptLanguage,
    "os_name": .device.osType,
    "os_version": .device.osVersion,
    "platform": .device.platformType,
    "user_properties": {
        "is_logged_in" : boolean(.actor."spt:userId")
    }
}

Demo playground.

Language tutorial.

Function documentation.

More examples.

Javadoc.

API introduction.

Build Status

Quick reference

Operation Explanation
. The context node
.<name> Get value of key "<name>" inside an object
.[<index>] Get value <index> inside an array
.[<from> : <to>] Array slicing
if (<expr>) <expr> else <expr> If test to decide which value to return
let <name> = <expr> Define a variable
$<name> Refer to a variable
[for (<expr>) <expr>] Transform an array
{for (<expr>) <expr> : <expr>} Transform an object
def <name>(<name>, <name>...) <expr> Declare a function
// <anything up to end of line> Comment
{ <key> : <expr> } Object constructor
{ <key> : <expr>, * : . } Specify one key, copy rest of input
5 * 7 + 23.2 Arithmetic operations
7 < 5 Comparators
7 < 5 and .foo == "yes" Boolean operators

Using the library

To include JSLT in your project, depend on:

<dependency>
  <groupId>com.schibsted.spt.data</groupId>
  <artifactId>jslt</artifactId>
  <version>0.1.11</version>
</dependency>

At runtime JSLT depends on Jackson, and nothing else.

To transform one JsonNode into another, do:

import com.schibsted.spt.data.jslt.Parser;
import com.schibsted.spt.data.jslt.Expression;

JsonNode input = ...;
Expression jslt = Parser.compileString(transform);
JsonNode output = jslt.apply(input);

For more alternatives, see the javadoc.

Command-line

To run transforms on the command-line, first build with ./gradlew clean shadowJar. Then you can run with:

java -cp build/libs/*.jar com.schibsted.spt.data.jslt.cli.JSLT transform.jslt input.json

The result is written to standard out.

Extension functions

You can implement your own functions and add them to the language. See the extension function tutorial.

Feedback

If you have questions about how to use JSLT, please ask the question on StackOverflow, with the tag jslt.

If you have problems, feature requests, or think you found a bug, please open an issue.

Status

The language design is not finished, so features may be added. The language as it stands is not likely to change.

The entire language is implemented, and all of the function library. Functions may be added.

The language has been used in production at Schibsted since January 2018, performing about 9 billion transforms per day, and many times more queries.

Building JSLT

To build JSLT as a jar file, run ./gradlew jar.

To build a fat jar with all dependencies included, run ./gradlew shadowJar.

To run the tests: ./gradlew check.

There is a pom.xml file, but Maven is not used for building JSLT, and the file is not intended to work. It's only there to make Github dependency tracking work.

More information

Developing a language for JSON processing: video of talk, slides only.

Running the playground yourself

Anthony Sparks is working on a VM-based implementation in Java

A paper describing (among other things) some of the ways Schibsted uses JSLT.

Visual Studio syntax highlighter for JSLT.

Apache Camel JSLT component.

Pincette event sourcing framework uses JSLT.

LICENSE

Copyright (c) 2018 Schibsted Marketplaces Products & Technology AS

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

What is missing

Things to be done:

  • Move the tests out into YAML files.
  • Write a proper spec with EBNF and everything.
  • Fix the syntax ambiguity problem with let and def.
  • Implement toString() throughout the object tree, so that it's possible to turn expressions back to strings.
  • Optimizer:
    • Optimize ... and boolean( ... ) by removing boolean().
    • Implement parse tree traversal API.
    • Make sure entire tree is traversed (inside function decls and variables, for example).
    • Complete constant folding. Particularly constant folding for variables would be valuable.
    • Inlining of functions.
    • Eliminate unused variables.
  • Use property-based testing and fuzz testing to harden the parser.

See also the list of ideas.

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