Giter Site home page Giter Site logo

formatjson's Introduction

formatjson

A simple JSON validator and formatter written in Rust.

For documentation check the docs.rs page.

Installation

cargo install formatjson

Usage

  • As a command-line tool:

    $ formatjson example.json
    Successfully formatted example.json
    $ echo '{"foo": "bar"}' | formatjson
    {
      "foo": "bar"
    }
  • As a library:

    fn main() {
        let json = formatjson::format_json(r#"{"foo":"bar"}"#).unwrap();
        println!("{}", json);
    }
    $ cargo run
    {
      "foo": "bar"
    }

Speed

Running it on this 25MB JSON file gave the following results:

$ hyperfine 'formatjson large.json'
Benchmark 1: formatjson large.json
  Time (mean ± σ):     400.1 ms ±   9.3 ms    [User: 359.4 ms, System: 31.9 ms]
  Range (min … max):   390.1 ms … 419.6 ms    10 runs

Averaging 400 milliseconds on my M1 MacBook Air, which is about 38 times faster than pretter, which took 15.27 seconds:

$ time npx prettier --check large.json
Checking formatting...
[warn] large.json
[warn] Code style issues found in the above file. Run Prettier to fix.
npx prettier --check large.json  26.14s user 11.57s system 246% cpu 15.279 total

formatjson's People

Contributors

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