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

Extra arrayElement after object in array #7

Open
e-tobi opened this issue Sep 9, 2023 · 3 comments
Open

Extra arrayElement after object in array #7

e-tobi opened this issue Sep 9, 2023 · 3 comments

Comments

@e-tobi
Copy link

e-tobi commented Sep 9, 2023

Having this json:

{"foo":[{"bar": "baz"}, null]}

I get this sequence of events:

  • JsonEventType.beginObject : null
  • JsonEventType.propertyName : foo
  • JsonEventType.beginArray : null
  • JsonEventType.beginObject : null
  • JsonEventType.propertyName : bar
  • JsonEventType.propertyValue : baz
  • JsonEventType.endObject : null
  • JsonEventType.arrayElement : null
  • JsonEventType.arrayElement : null
  • JsonEventType.endArray : null
  • JsonEventType.propertyValue : null
  • JsonEventType.endObject : null

After the object in the array an extra arrayElement with value null is emitted. This can't be ignored because there actually might be a null in the array.

@aeb-dev
Copy link
Owner

aeb-dev commented Sep 10, 2023

This is similar to this issue #6. arrayElement: value marks the end of one of the items of the array. If was storing the object I would have returned arrayElement: {"bar": "baz"} but I can not be sure of the size the object could be huge so I don't store and return it. Instead I just let the parser know that it is the end of current element and we are moving to next

@e-tobi
Copy link
Author

e-tobi commented Sep 11, 2023

Ok. I understand.

If you are ever going to reconsider this, maybe instead of propertyValue / arrayElement, having string/number/literal events feels a little bit closer to the JSON RFC specs. string/number/literal might even be reduced to a single 'literalValue" event with a dynamic value of type String, int, double, bool or null.

  • beginArray : no value
  • endArray : no value
  • beginObject : no value
  • endObject : no value
  • propertyName: String value
  • string: String value
  • number: double or int value
  • literal: true or false or null

I think this could be slightly easier for the consumer of the events.

@aeb-dev
Copy link
Owner

aeb-dev commented Sep 11, 2023

Currently, the parser does not have any state so it actually does not know what is it current depth or parent. And I am not sure whether what you introduced can be done without introducing some kind of state. I did not use any state because I believe this is simpler from the perspective of the parser.

With that said I am aware that, I am very opinionated/blind because of the current parser implementation so if you can come up with PR I would be happy to check. I am open to changes but no promises 😄

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