Giter VIP home page Giter VIP logo

jsonxf's Introduction

Jsonxf

A JSON transformer, written in Rust.

Provides fast pretty-printing and minimizing of JSON-encoded strings and streams, at the command line or within Rust programs.

Crate docs: https://docs.rs/jsonxf/

Installation

cargo install jsonxf

Command-line Examples

Pretty-print a string to the terminal, using two spaces to indent:

jsonxf -s '{"a": {"b": 2, "c": false}}'

Pretty-print and read a JSON file, using a tab character to indent:

jsonxf -t $'\t' <foo.json | less

Minimize a file and gzip it:

jsonxf -m <foo.json | gzip -c >foo-min.json.gz

Run jsonxf -h to see all configuration options.

Rust Example

In your Cargo.toml:

[dependencies]
jsonxf = "0.9"

In your code:

extern crate jsonxf;
let ugly_json = "{\"hello\":\"world\"}";
let pretty_json = jsonxf::pretty_print(ugly_json).unwrap();
assert_eq!(pretty_json, "{\n  \"hello\": \"world\"\n}\n");

Performance

Here are some benchmarks comparing Jsonxf 0.9's performance to several of its counterparts:

  • jq, the extremely flexible JSON processor.
  • jsonpp, a JSON pretty-printer written in Go.
  • serdexf, a trivial example using the serde_json and serde-transcode libraries. This implementation is not complete and is included for library comparison only.
  • cat is thrown in as well, for scale.

Test platform: MBP (early 2013), macOS 10.13.2, 3GHz i7, 8GB RAM.

See benchmark.rb for testing procedure.

Pretty-print test, 600MB minimized input (1M objects):

command time (s) relative time notes
cat 2.26 0.3x cat is a bad pretty-printer
jsonxf 7.76 1x
serdexf 9.33 1.2x no newlines between objects ๐Ÿ™
jsonpp 25.0 3.2x
jq -M . 67.0 8.6x

Minimize test, 850MB pretty-printed input (1M objects):

command time (s) relative time notes
cat 1.45 0.2x cat is a bad minimizer
jsonxf -m 6.78 1x
serdexf -m 7.30 1.1x
jsonpp - - minimizing is not supported ๐Ÿ˜ญ
jq -cM . 78.0 12x

Authorship and License

Copyright 2017-2018, Pete Gamache.

Jsonxf is released under the MIT License.

jsonxf's People

Contributors

gamache avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.