-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #98 from thenetrunna/master
shogdb: add json functionalities
- Loading branch information
Showing
49 changed files
with
12,604 additions
and
952 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
**/target | ||
jmespath/Cargo.lock | ||
.idea/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# CHANGELOG | ||
|
||
## 0.2.0 - 2017-09-26 | ||
|
||
* Now works with Serde 1.0: | ||
https://github.com/jmespath/jmespath.rs/pull/24 | ||
* impl `Error` for `JmespathError`: | ||
https://github.com/jmespath/jmespath.rs/pull/22 | ||
* Removed parentheses around `Fn` to fix syntactic error: | ||
https://github.com/jmespath/jmespath.rs/pull/20 | ||
|
||
## 0.1.1 - 2017-01-07 | ||
|
||
* Now works on stable by placing specialization behind the `specialized` | ||
feature flag. https://github.com/jmespath/jmespath.rs/pull/19 | ||
|
||
## 0.1.0 - 2016-12-15 | ||
|
||
* First somewhat stable release. | ||
|
||
## 0.0.1 - 2016-01-30 | ||
|
||
* Initial release. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Copyright (c) 2015 Michael Dowling | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# JMESPath for Rust | ||
|
||
Rust implementation of [JMESPath](http://jmespath.org), a query language for JSON. | ||
|
||
[Documentation](https://docs.rs/jmespath/) | ||
|
||
## Installing | ||
|
||
This crate is [on crates.io](https://crates.io/crates/jmespath) and can be used | ||
by adding `jmespath` to the dependencies in your project's `Cargo.toml`. | ||
|
||
```toml | ||
[dependencies] | ||
jmespath = "^0.3.0" | ||
``` | ||
|
||
If you are using a nightly compiler, or reading this when specialization in Rust | ||
is stable (see [rust#31844](https://github.com/rust-lang/rust/issues/31844)), then | ||
enable the `specialized` feature to switch on usage of specialization to get more | ||
efficient code: | ||
|
||
```toml | ||
[dependencies.jmespath] | ||
version = "^0.3.0" | ||
features = ["specialized"] | ||
``` | ||
|
||
## Examples | ||
|
||
```rust | ||
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()); | ||
``` |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[package] | ||
name = "jmespathimpl" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
|
||
[lib] | ||
path = "src/lib.rs" | ||
crate-type = ["staticlib"] | ||
|
||
[dependencies] | ||
jmespath = { path = "../jmespath" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
use jmespath; | ||
use jmespath::Expression; | ||
use jmespath::Variable; | ||
|
||
use std::ffi::CStr; | ||
use std::ffi::CString; | ||
use std::os::raw::c_char; | ||
|
||
#[no_mangle] | ||
pub extern "C" fn jmespath_filter_json(json: *const c_char, filter: *const c_char) -> *mut c_char { | ||
let c_json: &CStr = unsafe { CStr::from_ptr(json) }; | ||
let c_filter: &CStr = unsafe { CStr::from_ptr(filter) }; | ||
|
||
let rust_json: &str = c_json.to_str().unwrap(); | ||
let rust_filter: &str = c_filter.to_str().unwrap(); | ||
|
||
let expr: Expression = jmespath::compile(rust_filter).unwrap(); | ||
|
||
// Parse some JSON data into a JMESPath variable | ||
let data: Variable = jmespath::Variable::from_json(rust_json).unwrap(); | ||
|
||
// Search the data with the compiled expression | ||
let result: String = expr.search(data).unwrap().to_string(); | ||
|
||
let c_result: CString = CString::new(result).unwrap(); | ||
return c_result.into_raw(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
[package] | ||
name = "jmespath" | ||
version = "0.3.0" | ||
authors = ["Michael Dowling <[email protected]>"] | ||
description = "Rust implementation of JMESPath, a query language for JSON" | ||
readme = "../README.md" | ||
keywords = ["json", "jmespath", "query"] | ||
homepage = "https://github.com/jmespath/jmespath.rs" | ||
repository = "https://github.com/jmespath/jmespath.rs" | ||
documentation = "https://docs.rs/jmespath/" | ||
license = "MIT" | ||
build = "build.rs" | ||
edition = "2018" | ||
|
||
[dependencies] | ||
serde = { version = "1", features = ["rc"] } | ||
serde_json = "1" | ||
lazy_static = "1.4" | ||
|
||
[build-dependencies] | ||
serde_json = "1" | ||
slug = "0.1" | ||
|
||
[dev-dependencies] | ||
bencher = "0.1.5" | ||
serde_derive = "1" | ||
|
||
[[bench]] | ||
name = "generated" | ||
harness = false | ||
|
||
[features] | ||
# `sync` utilizes an Arc instead of an Rc for JMESPath runtime variables. | ||
# Using an Arc allows you to share compiled expressions across threads. | ||
sync = [] | ||
# `specialized` enables the use of specialization for more efficient code | ||
# however at time of writing it is unstable & so requires a nightly compiler. | ||
# See https://github.com/rust-lang/rust/issues/31844 for the latest status. | ||
specialized = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
//! Generated benchmarks. Benchmarks are generated in build.rs and are | ||
//! sourced from tests/compliance/benchmarks.json | ||
//#![feature(test)] | ||
|
||
//extern crate bencher; | ||
|
||
use bencher::*; | ||
use jmespath::{compile, parse, Rcvar, Variable}; | ||
|
||
include!(concat!(env!("OUT_DIR"), "/benches.rs")); |
Oops, something went wrong.