GithubHelp home page GithubHelp logo

zhutony / jmespath.rs Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jmespath/jmespath.rs

0.0 2.0 0.0 545 KB

Rust implementation of JMESPath, a query language for JSON

License: MIT License

Rust 100.00%

jmespath.rs's Introduction

JMESPath for Rust

Build Status Coverage Status Current Version Gitter

Rust implementation of JMESPath, a query language for JSON.

Documentation

Installing

This crate is on crates.io and can be used by adding jmespath to the dependencies in your project's Cargo.toml.

[dependencies]
jmespath = "^0.2.0"

If you are using a nightly compiler, or reading this when specialization in Rust is stable (see rust#31844), then enable the specialized feature to switch on usage of specialization to get more efficient code:

[dependencies.jmespath]
version = "^0.2.0"
features = ["specialized"]

Examples

extern crate jmespath;

let expr = jmespath::compile("foo.bar").unwrap();

// Parse some JSON data into a JMESPath variable
let json_str = r#"{"foo": {"bar": true}}"#;
let data = jmespath::Variable::from_json(json_str).unwrap();

// Search the data with the compiled expression
let result = expr.search(data).unwrap();
assert_eq!(true, result.as_boolean().unwrap());

jmespath! compiler plugin

The jmespath-macros crate provides the jmespath! macro used to statically compile JMESPath expressions.

By statically compiling JMESPath expressions, you pay the cost of parsing and compiling JMESPath expressions at compile time rather than at runtime, and you can be sure that the expression is valid if your program compiles.

Note: This only works with a nightly compiler.

#![feature(plugin)]

#![plugin(jmespath_macros)]
extern crate jmespath;

fn main() {
    // Create our statically compiled expression. The build will fail
    // if the expression is invalid.
    let expr = jmespath!("foo.bar");

    // Parse some JSON data into a JMESPath variable
    let json_str = r#"{"foo": {"bar": true}}"#;
    let data = jmespath::Variable::from_json(json_str).unwrap();
    let result = expr.search(data).unwrap();
    assert_eq!(true, result.as_boolean().unwrap());
}

jmespath.rs's People

Contributors

mtdowling avatar caspark avatar euclio avatar messense avatar silvio avatar twz123 avatar petrochenkov avatar yrashk avatar forensicmatt avatar

Watchers

James Cloos avatar  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.