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

Any way to know the current object being parsed? #134

Open
TheSauceMan opened this issue Mar 11, 2020 · 2 comments
Open

Any way to know the current object being parsed? #134

TheSauceMan opened this issue Mar 11, 2020 · 2 comments

Comments

@TheSauceMan
Copy link

Hi,
I am dealing with very large objects and potentially large arrays of stuff. I'm not sure if I can tell from start_object or end_object the name of the object that was being parsed. For instance, if start_object told me the name I could choose to ignore that name (by passing a dummy dictionary) rather than loading it into memory.

Take this for example:

{
  "hello": "world",
  "obj": {
    "obj_val": "first_obj_val",
    "obj_val2": "second_obj_val",
    "obj_val3": 3
  },
  "arr": [
    2, 4, 6, 8
  ]
}

I only get callbacks on start of the object (twice, but nothing telling me it is unnamed or called "obj"), the end of the "obj" and main object, the end of the "arr" array, and strings for "first_obj_val" and "second_obj_val". I wish I knew the keys / names for any of these.

For example, there's no way of knowing that "first_obj_val" refers to "obj_val" (or better yet, "obj.obj_val") until the very end.

Am I doing it wrong?

@lelit
Copy link
Contributor

lelit commented Mar 12, 2020

No, there's no way of knowing that, indeed.

Maybe the decoder class could expose that information, possibly as a property returning something like a JSON Pointer?

@lelit
Copy link
Contributor

lelit commented Mar 12, 2020

Looking at the code, it does not seem very difficult to do that: internally, the decoding logic uses an handler that has access the decoder instance: the handler maintains a stack of context structures, one for each level, so that property could basically be implemented by traversing the stack and building a pointer value.

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

No branches or pull requests

2 participants