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

Support for streams of JSON data and incremental parsing? #426

Open
KKhanhH opened this issue Apr 23, 2024 · 4 comments
Open

Support for streams of JSON data and incremental parsing? #426

KKhanhH opened this issue Apr 23, 2024 · 4 comments

Comments

@KKhanhH
Copy link

KKhanhH commented Apr 23, 2024

Hi,

I'm researching switching from rapidJSON to DAW JSON link for my project in order to avoid allocation. One of the features that rapidJSON supports is a custom stream that can be used for its parser. My project uses a large JSON file, containing a few objects with large nested arrays, which is then compressed. I would like to avoid having to allocate a large string buffer for the entire decompressed JSON file and instead use a small buffer for a part of the decompressed data and then incrementally deserialize the nested arrays and outer arrays into their own classes. Is something like this possible with this library?

Here is an example of what I'm looking for

Sample JSON

{
    "class1": [
        {
            //regular old class
        },
        {
            //regular old class
        }
    ],
    "obj1": {
        "header": ["name","value","nestedClass"],
        "nestedClassHeader": ["name","value","value2"],
        "data": [
            [
                "str", 1.324, [["abc",1,1.0],["cdf",2,2.5]] // many more arrays
            ],
            ["str2", 1.234, [["abc",1,1.0],["cdf",2,2.5]]], //many more arrays
            
        ]
    },
    "obj2": {
        //same structure as above
    }
}

Obj 1 and 2 would contain name, value and then a vector of "nestedClasses"

@beached
Copy link
Owner

beached commented Apr 23, 2024

does something like https://github.com/beached/daw_json_link/blob/release/docs/cookbook/unknown_types_and_raw_parsing.md handle that for you? then later use something like a json_array_iterator over that member?

@KKhanhH
Copy link
Author

KKhanhH commented Apr 23, 2024

From the example, I can't tell if json_raw accepts an incomplete json value. Would it be able recognize obj1's name and the other members "header" and "nestedClassHeader" if the string only contained up to say 3 array elements of ob1["data"] . I am trying to avoid storing the entire array all at once since the array nested inside of "data"'s elements could contain several thousand arrays, on top of data possibly containing several thousand elements.

@beached
Copy link
Owner

beached commented Apr 23, 2024

It defaults to a json_value which would hold the character positions of that member(like a string_view) and let you parse it later, it just skips it for now.

@KKhanhH
Copy link
Author

KKhanhH commented Apr 23, 2024

Ah okay, that sounds like it will need to be a seekable stream then. Are there any examples for constructing a json_value from a custom stream class rather than a contiguous string/string_view?

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