Live data from Hacker News

On-demand JSON: A better way to parse documents?

onlinelibrary.wiley.com

11–20 of 55 posts

Re: On-demand JSON: A better way to parse documents?

#11

> The JSON syntax is nearly a strict subset of the popular programming language JavaScript. What JSON isn’t valid JS?

The one thing I've seen mentioned before is the use of "__proto__" as a object property key. Though it's valid syntax in both JSON and JS like any other string key, it somewhat uniquely does something different if interpreted as JS (setting the created object's prototype) than it does if interpreted as JSON.

Re: On-demand JSON: A better way to parse documents?

#13

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.

You need a parser for validation, - preferably a fast, possibly even a streaming one.

Re: On-demand JSON: A better way to parse documents?

#15

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.

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.

Re: On-demand JSON: A better way to parse documents?

#17

So they're creating a DOM-like api in front of a sax style parser and getting faster results (barring FPGA and GPU research). It's released as part of SIMDJson. I wonder if that kind of front end was done in the age of SAX parsers? Such a well-written paper.

SAX is a push parser, presumably this is on top of a pull API like StAX.

The Jakarta JSON streaming API sort of gets at this (sort of):

https://jakarta.ee/specifications/platform/9/apidocs/jakarta...

The basic interface to a JSON document is something like an iterator, which lets you advance through the document, token by token, and read out values when you encounter them. So if you have an array of objects with x and y fields, you read a start of array, start of object, key "x", first x value, key "y", first y value, end of object, start of object, key "x", second x value, key "y", second y value, end of object, etc. Reading tokens, not anything tree/DOM-like. But there are also methods getObject() and getArray(), which pull a whole structure out of the document from wherever the iterator has got to. So you could read start of array, read object, read object, etc. That lets you process a document incrementally, without having to materialise the whole thing as a tree, but still having a nice tree-like interface at the leaves.

In principle, you could implement getObject() and getArray() in a way which does not eagerly materialise their contents - each node could know a range in a backing buffer, and parse contents on demand. But i don't think implementations actually do this.

Wrapping a tree-like interface round incremental parsing that doesn't require eager parsing or retaining arbitrary amounts of data, and doesn't leak implementation details, sounds astoundingly hard, perhaps even impossible. But then i am not Daniel Lemire. And i have not read the paper.

Re: On-demand JSON: A better way to parse documents?

#18

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.

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.

Re: On-demand JSON: A better way to parse documents?

#19
Why not just use msgpack? The advantage of JSON is that support is already built in to everything and you don't have to think about it.

If you start having to actually make an effort to fuss with it, then why not consider other formats?

This does have nice backwards compatibility with existing JSON stuff though, and sticking to standards is cool. But msgpack is also pretty nice.

Re: On-demand JSON: A better way to parse documents?

#20
post #18

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.

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.

Post reply on HN