GithubHelp home page GithubHelp logo

jmespath / jmespath.rs Goto Github PK

View Code? Open in Web Editor NEW
121.0 9.0 25.0 615 KB

Rust implementation of JMESPath, a query language for JSON

License: MIT License

Rust 100.00%
jmespath json rust query-language

jmespath.rs's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jmespath.rs's Issues

CANARY ISSUE - Please acknowledge and close if seen by maintainer

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 πŸ˜„

Release 0.2

It would be nice to release a new version with the Error impl and serde 1.0 support πŸ˜„

Problem with simple testcase

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)

Adding jmespath to dependencies causes compile error

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.

Feature: recursive descent operator

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.

Add Cargo.lock to the repository

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.

struct to Variable question

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);
}

Add line/col support for runtime errors?

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.

Add code generation for benchmarks

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):

  • lexing (e.g., tokenize_TESTNUMBER_foo_dot_bar_dot_baz)
  • parsing (e.g., parse_TESTNUMBER_foo_dot_bar_dot_baz)
  • interpret (e.g., 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\"}}}"),
    // ...
];

Add stack traces to runtime errors?

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.

compiling master serde_json 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

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.