πŸ”¨ A JSON parser that will return span informations

Overview

Spanned Json Parser   Build Status Latest Version

This crate is a json parser that will return span information for values, which mean lines and column number. It is also compatible with serde so you can serialize it to any other struct that implements Deserialize

Why use it ?

One of the main use case is to do validation after parsing. By having the line and col number, you can tell really precisely to a user where a value is invalid

How to use it ?

The crate expose a Value that is similar to serde, and wraps everything into this struct:

pub struct Position {
    pub col: usize,
    pub line: usize,
}

pub struct SpannedValue {
    pub value: Value,
    pub start: Position,
    pub end: Position,
}

Parsing

use spanned_json_parse::parse;
use std::fs;

fn main() {
    let json = fs::read_to_string(path).unwrap();

    let parsed = parse(&json);

    println!("Parsed: {:#?}", parsed);
}

Serializing in a struct

use serde::Deserialize;
use spanned_json_parser::parse;

#[derive(Deserialize)]
struct Test {
    pub hello: String,
}

fn main() {
    let json = r#"{"hello": "world"}"#;

    let parsed = parse(json).unwrap();

    let test: Test = serde_json::from_value(serde_json::to_value(parsed).unwrap()).unwrap();

    println!("Test hello: {}", test.hello);
}

Performance

Here are the outputs of the benchmark. Everything was tested on a Macbook Pro M1, so keep in mind that this numbers are here to give you an idea of the performance, but might not be representative of the reality:

Parser ./benches/data/twitter.json
time:   [10.220 ms 10.279 ms 10.334 ms]
thrpt:  [58.280 MiB/s 58.589 MiB/s 58.932 MiB/s]

Parser ./benches/data/citm_catalog.json
time:   [18.204 ms 18.281 ms 18.353 ms]
thrpt:  [89.752 MiB/s 90.102 MiB/s 90.486 MiB/s]

Parser ./benches/data/canada.json
time:   [42.026 ms 42.188 ms 42.341 ms]
thrpt:  [50.702 MiB/s 50.886 MiB/s 51.082 MiB/s]
You might also like...
jf "jf: %q" "JSON Format"

jf jf "jf: %q" "JSON Format" jf is a jo alternative to help safely format and print JSON objects in the commandline. However, unlike jo, where you bui

A simple CLI tool for converting CSV file content to JSON.

fast-csv-to-json A simple CLI tool for converting CSV file content to JSON. ζˆ‘θŠ±δΊ†δΈ€ε€‹ε°ζ™‚ζ“ε‡ΊδΎ†οΌŒζŽ₯θ‘—ε„ͺεŒ–δΊ†ε…©ε€©ηš„εΏ«ι€Ÿ CSV 轉 JSON CLI 小ε·₯ε…· Installation Install Rust with ru

This project returns Queried value from SOAP(XML) in form of JSON.

About This is project by team SSDD for HachNUThon (TechHolding). This project stores and allows updating SOAP(xml) data and responds to various querie

 This CLI utility facilitates effortless manipulation and exploration of TOML, YAML, JSON and RON files.
This CLI utility facilitates effortless manipulation and exploration of TOML, YAML, JSON and RON files.

πŸ“πŸ’»πŸ”πŸ”§ This CLI utility facilitates effortless manipulation and exploration of TOML, YAML, JSON and RON files.

List key patterns of a JSON file for jq.
List key patterns of a JSON file for jq.

jqk jqk lists key patterns of a JSON file for jq. Why? jq is a useful command line tool to filter values from a JSON file quickly on a terminal; howev

Generates an Anchor CPI crate from a JSON IDL.

anchor-gen Generates a crate for cross-program invocations to an Anchor program from a JSON IDL. Usage In a new crate, write: anchor_gen::generate_cpi

Tool to allow parsing large JSON files without laoding into memory
Tool to allow parsing large JSON files without laoding into memory

Tool to allow parsing large JSON files without laoding into memory. Developed in Rust with adapters in other programming langauges for easy adoption

Functional command-line JSON processor
Functional command-line JSON processor

rq rq is a tiny functional language with which you can manipulate JSON. Basically, it is (an insignificant subset of!) jq, written in Rust. NOTE: This

Infer a JSON schema from example data, produce nonsense synthetic data (drivel) according to the schema

drivel drivel is a command-line tool written in Rust for inferring a schema from an example JSON (or JSON lines) file, and generating synthetic data (

Owner
Jules Guesnon
Software engineer that loves all kinds of technologies, but if it's statically typed it's better
Jules Guesnon
A language parser tool to build recursive descent top down parser.

lang-pt A language parser tool to generate recursive descent top down parser. Overview Parsers written for the languages like Javascript are often cus

Creative Forest 7 Jan 4, 2023
An ultra-fast CLI app that fixes JSON files in large codebase or folders

minosse An ultra fast CLI app that fixes json files in large codebase or folders USAGE: minosse [OPTIONS] <input-dir> FLAGS: -h, --help Prints

Antonino Bertulla 5 Oct 17, 2022
A simple CLI for combining json and yaml files

A simple CLI for combining json and yaml files

Avencera 16 Jul 4, 2022
A Rust CLI to provide last publish dates for packages in a package-lock.json file

NPM Package Age A Rust CLI which if you provide a npm lockfile (package-lock.json to start), it will give you a listing of all of the packages & the l

Benjamin Lannon 1 Feb 4, 2022
This is a simple command line application to convert bibtex to json written in Rust and Python

bibtex-to-json This is a simple command line application to convert bibtex to json written in Rust and Python. Why? To enable you to convert very big

null 3 Mar 23, 2022
hj is a command line tool to convert HTTP/1-style text into JSON

hj hj is a command line tool to convert HTTP/1-style text into JSON. This command is inspired by yusukebe/rj, which is a standalone HTTP client that s

FUJI Goro 10 Aug 21, 2022
CLI application to run clang-format on a set of files specified using globs in a JSON configuration file.

run_clang_format CLI application for running clang-format for an existing .clang-format file on a set of files, specified using globs in a .json confi

martin 6 Dec 16, 2022
A small CLI tool to query ArcGIS REST API services, implemented in Rust. The server response is returned as pretty JSON.

A small CLI tool to query ArcGIS REST API services, implemented in Rust. The server response is returned as pretty JSON.

Andrew Vitale 2 Apr 25, 2022
CLI application to run clang-tidy on a set of files specified using globs in a JSON configuration file.

run-clang-tidy CLI application for running clang-tidy for an existing .clang-tidy file on a set of files, specified using globs in a .json configurati

martin 7 Nov 4, 2022
A Faster(⚑) formatter, linter, bundler, and more for JavaScript, TypeScript, JSON, HTML, Markdown, and CSS Lapce Plugin

Lapce Plugin for Rome Lapce-rome is a Lapce plugin for rome, The Rome is faster ⚑ , A formatter, linter, compiler, bundler, and more for JavaScript, T

xiaoxin 7 Dec 16, 2022