Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Placeholders in a path #79

Open
Adam-Vandervorst opened this issue Apr 26, 2024 · 1 comment
Open

Placeholders in a path #79

Adam-Vandervorst opened this issue Apr 26, 2024 · 1 comment

Comments

@Adam-Vandervorst
Copy link

Adam-Vandervorst commented Apr 26, 2024

Is your feature request related to a problem? Please describe.

If you want to project out a simple structure out of a large JSON you have two options:
a) Formalize the large JSON scheme, parse that, and post-process it
b) Get the parts you need with using paths

However, a) is expensive for the programmer, and b) is quite limited and computationally expensive if you want to get around that

Describe the solution you'd like

let vs = sonic_rs::get(line, sonic_rs::pointer!["aliases", "en", Index, "value"])

and

let o = sonic_rs::get(line, sonic_rs::pointer!["aliases", Key, 0, "value"])

Describe alternatives you've considered

for i in 0..MAX_ARRAY_SIZE { 
  match sonic_rs::get(line, sonic_rs::pointer!["aliases", "en", i, "value"]) {
    Ok(r) => { vs.push_back(r) }
    Err(_) => { break }
  }
}

and

for lang in languages { 
  match sonic_rs::get(line, sonic_rs::pointer!["aliases", lang, 0, "value"]) {
    Ok(r) => { o.insert(lang, r) }
    Err(_) => { continue }
  }
}

Additional context

Think about it as using a well-typed Glob for your JSON.
Notably, the workaround gets quadratically worse when you have more placeholders in your path.

@liuq19
Copy link
Collaborator

liuq19 commented Apr 29, 2024

Yes, pointer! has limitations when it comes to retrieving multiple keys from a large JSON.

If we want to perform quick and flexible searches on large JSON data as above, it is advisable to support the JSONPath RFC. While it is included in the roadmap, it may not be completed shortly.

There is an existing high-performance JSONPath library available at https://github.com/rsonquery/rsonpath that can be used for your purpose.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants