jmespath / jmespath.rs Goto Github PK
View Code? Open in Web Editor NEWRust implementation of JMESPath, a query language for JSON
License: MIT License
Rust implementation of JMESPath, a query language for JSON
License: MIT License
Is it possible to add WASM support to jmespath?
https://rustwasm.github.io/book/reference/add-wasm-support-to-crate.html
Hi all! Thanks so much for creating this crate.
Due to the current broken compilation against latest serde_json
(see #33), please pardon me for creating this simple canary issue. It's simply a way to discover whether this crate has a maintainer who is engaged with Github.
If you are a maintainer, please do feel free to acknowledge, and simply close the issue!
Thanks again π
It would be nice to release a new version with the Error
impl and serde 1.0 support π
Amazing Library.
Love the Custom Function runtime ability.
Hi,
is this project still active?
I have a wrong behaviour with the (compliance) test cases. I don't know what is going wrong, but something bad happen here.
I added two test cases like this one:
diff --git a/tests/compliance/basic.json b/tests/compliance/basic.json
index d550e96..38b41db 100644
--- a/tests/compliance/basic.json
+++ b/tests/compliance/basic.json
@@ -92,5 +92,20 @@
"result": "bar"
}
]
+},
+{
+ "given": {"a": true},
+ "cases": [
+ {
+ "comment": "simple basic test true",
+ "expression": "a",
+ "result": true
+ },
+ {
+ "comment": "simple basic test false",
+ "expression": "a",
+ "result": false
+ }
+ ]
}
]
I get this result:
test test_basic_0_0_simple_basic_test_true ... ok
test test_basic_0_1_simple_basic_test_false ... ok
My expectation was that one of this tests should fail. I'm wrong?
Some investigation: The characteristic of the problem is that Assertion::assert
returns with an Ok(())
because r.as_string()
returns a None
. The function as_string()
returns only a string object if the Variable
is a String
typed value. (doc/src/jmespath/variable.rs.html#170-175)
I added jmespath
to an existing project, and immediately started getting weird compile errors. I tried replicating with a blank project, added the dependency, and got the same result:
$ cargo new mytest
Created binary (application) `mytest` package
$ echo 'jmespath = "^0.2.0"' >> mytest/Cargo.toml
$ cd mytest
$ cargo build
Updating crates.io index
Compiling serde v1.0.125
Compiling ryu v1.0.5
Compiling serde_json v1.0.64
Compiling deunicode v0.4.3
Compiling itoa v0.4.7
Compiling lazy_static v0.2.11
Compiling slug v0.1.4
Compiling jmespath v0.2.0
error[E0603]: enum `ErrorCode` is private
--> /home/nturett/.cargo/registry/src/github.com-1ecc6299db9ec823/jmespath-0.2.0/src/variable.rs:9:32
|
9 | use serde_json::error::{Error, ErrorCode};
| ^^^^^^^^^ private enum
|
note: the enum `ErrorCode` is defined here
--> /home/nturett/.cargo/registry/src/github.com-1ecc6299db9ec823/serde_json-1.0.64/src/error.rs:176:1
|
176 | pub(crate) enum ErrorCode {
| ^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0624]: associated function `syntax` is private
--> /home/nturett/.cargo/registry/src/github.com-1ecc6299db9ec823/jmespath-0.2.0/src/variable.rs:1205:36
|
1205 | _ => return Err(Error::syntax(ErrorCode::KeyMustBeAString, 0, 0)),
| ^^^^^^ private associated function
error: aborting due to 2 previous errors
Some errors have detailed explanations: E0603, E0624.
For more information about an error, try `rustc --explain E0603`.
error: could not compile `jmespath`
I'm relatively new to Rust, so if I'm doing something wrong please let me know.
Being discussed to formally be added to the spec here: jmespath/jmespath.py#110
If I can get this library back up to working order including the macros, the next thing I'd like to see is an optional feature to add a non-standard recursive descent operator while the spec above gets discussed. Gated behind a feature like "nonstandard-recursive-descent", it would enable parsing ..
in the same manner as JSONPath and E4X, which expands the flexibility of jmespath.
Once a standard solution became defined the spec, this feature could be sunset or default to the official solution.
http://www.joshmatthews.net/blog/2015/10/creating-a-c-api-for-a-rust-library/ could prove useful for guidance.
Can you please add Cargo.lock to the repository (and keep it up-to-date)? Itβs important for Linux distributions packaging jmespath to achieve reproducible builds.
Thanks for the awesome library! I have started using it in one of my projects (https://github.com/forensicmatt/RustyUsn#query-records) to help filter/format output and plan to add it to many more.
Currently I am having to convert a record to JSON string, then to a Variable via Variable::from_json(). But, it would be awesome if I could just serialize my struct to a Variable and save time by skipping the JSON middle man. It seems like this might be possible using the ToJmespath trait. However, I do not understand traits very well. If this is the case and I can go from struct to Variable, could you help me with an example? Maybe something simple like turning the following structures into a Variable:
extern crate jmespath;
use jmespath::*;
#[derive(Debug)]
struct TestStruct1{
test_field1: u32,
test_field2: u16,
test_field3: u16,
test_field4: String
}
impl ToJmespath for TestStruct1 {
#[inline]
fn to_jmespath(self) -> Rcvar {
Rcvar::new(Variable::from(self))
}
}
#[derive(Debug)]
struct TestStruct2{
test2_field1: u32,
test2_field2: u16,
test2_field3: String,
test2_field4: TestStruct1,
}
fn main() {
let test_struct = TestStruct2 {
test2_field1: 32,
test2_field2: 16,
test2_field3: String::from("TestStruct2!"),
test2_field4: TestStruct1 {
test_field1: 32,
test_field2: 16,
test_field3: 16,
test_field4: String::from("TestStruct1!")
}
};
println!("{:#?}",test_struct);
}
it would be interesting to see if a py03 python binding could be created for this repo.
https://ohadravid.github.io/posts/2023-03-rusty-python/
Can you create a new release so that 4490894 is available through cargo?
It would be nice to be able to see the line number and column associated with a runtime error. This would require that AST nodes also include the text position that they are associated with. Barring a much more complex implementation, because the AST is much more abstract than a parse tree, we may only be able to give an approximation of where the error occurred rather than the actual position.
It would be nice to be able to code-gen the benchmarks from a list of expressions. The generated code would then create a normalized benchmark name for each of the following (where TESTNUMBER if the position in the list of expressions):
tokenize_TESTNUMBER_foo_dot_bar_dot_baz
)parse_TESTNUMBER_foo_dot_bar_dot_baz
)interpret_TESTNUMBER_foo_dot_bar_dot_baz
benches could then be generated from either a JSON file or a macro based DSL:
let benches = vec![
add_bench!("foo", "{\"foo\":true}"),
add_bench!("foo.bar.baz", "{\"foo\":{\"bar\":{\"baz\":\"bam\"}}}"),
add_bench!("foo.bar.invalid", "{\"foo\":{\"bar\":{\"baz\":\"bam\"}}}"),
// ...
];
Adding support for some kind of stack trace to runtime errors would be nice as it would show how complex expressions (especially expressions involving expression references) arrived at an error.
serde_json errors when compiling master:
error[E0603]: enum `ErrorCode` is private
--> src\variable.rs:9:32
|
9 | use serde_json::error::{Error, ErrorCode};
| ^^^^^^^^^
error[E0624]: method `syntax` is private
--> src\variable.rs:1205:29
|
1205 | _ => return Err(Error::syntax(ErrorCode::KeyMustBeAString, 0, 0)),
| ^^^^^^^^^^^^^
error: aborting due to 2 previous errors
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.