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

JSON root can be other types #3

Closed
miloyip opened this issue Jan 23, 2016 · 3 comments
Closed

JSON root can be other types #3

miloyip opened this issue Jan 23, 2016 · 3 comments

Comments

@miloyip
Copy link

miloyip commented Jan 23, 2016

Recently I was suggested to add mm_json.h to nativejson-benchmark but I found that the root of JSON parsed by mm_json.h must be object type.

When parsing an invalid JSON ["Extra close"]] the parser seems go into dead-loop.

P.S. How to get number of key-value pairs at the root?

@vurtun
Copy link
Owner

vurtun commented Jan 23, 2016

but I found that the root of JSON parsed by mm_json.h must be object type.

I looked it up and as far as I know JSON root nodes are only allowed to be either an object or an array. I then check it and added some addition test and as far as I can tell both work fine. Could you point me to an example that did not work so I can check what went wrong.

When parsing an invalid JSON ["Extra close"]] the parser seems go into dead-loop

This is taken from my documentation at the top of the header:

It is important to note that while every valid JSON tree should be parsable
without problems, there is no guarantee that any invalid input is detected as
such, since the parser has only minimal validation.

I know this is probably not a perfect situation but the internal simplicity of the state machine has complex consequences for content validation. So in your given case ["Extra close"]] the object ends with the first ] since the array is now complete. I tested the exact example you gave me and I don't get a dead-loop. So I probably have to ask you for some code to check what API you use and how you use it.

P.S. How to get number of key-value pairs at the root?

Currently do not have a way. I don't have much time right now but I can check later if there is a way to add it.

@miloyip
Copy link
Author

miloyip commented Jan 23, 2016

In the older RFC4267, root value of JSON must be object or array. But this is relaxed in RFC7159 and ECMA-404, such that any types can be the root. However, It seems the current design of MMX mm_json.h does not store the root value in tokens, so it can not differentiate between object or array anyway.

I have submitted my current integration in this branch. During the conformance tests, when it parses some invalid JSONs it goes to dead loop. You may check the test code. To make the build easier, you can delete all files in /src/tests/ except rapidjsontest.cpp and mmxtest.cpp, then run make in the project root.

By the way, I have just added another token-based parser jsmn, which stores the root value as the first token. You may also refer to its test code.

vurtun added a commit that referenced this issue Jan 23, 2016
@vurtun
Copy link
Owner

vurtun commented Jan 23, 2016

I am sick of it. I will remove the library. Do your benchmark without it. I don't care about all these standards and the expectation that come with it. If I wanted to have something like jsmn than I would have create something along side of or used it directly. Probably for the best so there is one less shitty json parser in this world.

@vurtun vurtun closed this as completed Jan 23, 2016
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