GithubHelp home page GithubHelp logo

JSON root can be other types about lib HOT 3 CLOSED

vurtun avatar vurtun commented on August 24, 2024
JSON root can be other types

from lib.

Comments (3)

vurtun avatar vurtun commented on August 24, 2024

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.

from lib.

miloyip avatar miloyip commented on August 24, 2024

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.

from lib.

vurtun avatar vurtun commented on August 24, 2024

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.

from lib.

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.