Hacker News new | ask | show | jobs
by fanseepawnts 860 days ago
Sorry, I would never use this. Before I consume any json from any source or for any purpose I validate it. Lazy loading serves no purpose if you need validation.

Hint: you need validation.

6 comments

If you already know it's validated and coming from a trusted source there is no reason to validate it again. For example json from a database that only allows inserting valid json. In such cases even the structure might be known and some assumptions can be safely made.
Sorry theres no such thing as prevalidated JSON. You can do it in a sidecar all you want.

In-process validation is required. There are no trusted sources. Your confusing valid json with valid json according to a schema for a specific purpose.

Lazy loading JSON parsers have no nead to exist, at all, ever. This is why they dont exist.

There are cases where the json does not come from a user input and can be trusted without a validation layer.

Also you may want to stream-validate it.

You need a parser for validation, - preferably a fast, possibly even a streaming one.
Which this is not.

A validating parser, that is. The paper clearly indicates that invalid JSON like [1, 1b] will pass, unless your code happens to try and decode the 1b.

The purpose seems to be for when parsing a JSON document where large parts of it are irrelevant to your use case. It seems cursed, but it seems that using this method you can leave lee-way for unparsed parts and still validate what you are actually using, if the parser is robust enough.
You don't need to load the entire JSON object as a DOM into RAM just to validate it. Validation can easily be done using a stack and iteration with space complexity being the depth of the JSON (stack) and time being linear to the length of the object.
smdjson is validating as it moves through the file