Giter Site home page Giter Site logo

Comments (6)

MeirShpilraien avatar MeirShpilraien commented on June 18, 2024 1

Yes, exactly.

from jsonpath.

freestrings avatar freestrings commented on June 18, 2024 1

That's a good idea. Thanks in advance for the PR. 👍

from jsonpath.

freestrings avatar freestrings commented on June 18, 2024

I have a question. What do you mean by custom struct?

from jsonpath.

MeirShpilraien avatar MeirShpilraien commented on June 18, 2024

I mean that the json structure (in memory) is not a serde_json::Value. Instead, we use our own structure (specifically in our use-case it's even C implemented). Imagine for example that you want some extra metadata per node in the json structure, you can not use serde_json::Value but it is easy to create your own struct and just implement Serialize and Deserialize to be able to use it with serde_json for serialization and deserialization. But now I also want to be able to perform a jsonpath query on this struct and this is why I open this issue :).

I imagine we can define a trait such that each object that wants to be jsonpath "compatible" will need to implement this trait (for sure the implementation for serde_json::Value will come built-in). The trait can define functions like IterValues for array iteration or IterItems for object iteration, it will define a function to get the type of the json object and for sure get primitive values (strings, number, boolean, ...).

For existing users, the API will stay exactly the same, but it will open a door for more users to be able to use this library.

WDYT?

from jsonpath.

freestrings avatar freestrings commented on June 18, 2024

I didn't understand exactly. Can I understand as below?

let v = TestStruct { ... };
let result = jsonpath::select(&v, "$.name").unwrap();

from jsonpath.

mattmart3 avatar mattmart3 commented on June 18, 2024

Maybe this trait could be useful to add (and retrieve) other metadata to the json node structure, such as the reference to the parent node or to the key string of the node. For instance I submitted a PR (#84) that implements the parent operator by the mean of a HashMap to relate each node to its parent. Of course by adding the parent reference to a more generic Node struct the implementation would be much more clean and efficient. Similarly, to implement the key operator (issue #69), one could add the key string reference to each node.
What do you think?

from jsonpath.

Related Issues (20)

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.