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

  • 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.

  • 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.

  • Alternatively, jsonl/ndjson. The largest parts of jsons are usually arrays, not dictionaries. So you can e.g.:

      {<a header about foos and bars>}
      {<foo 1>}
      ...
      {<foo N>}
      {<bar 1>}
      ...
      {<bar N>}
    
    It is compatible with streaming, database json columns, code editors.

  • I don't really understand what's new here compared to what SIMDJSON supported already.

    Anyways, it's the best JSON parser I found (in any language), I implemented fastgron (https://github.com/adamritter/fastgron) on top of it because of the on demand library performance.

    One problem with the library was that it needed extra padding at the end of the JSON, so it didn't support streaming / memory mapping.

  • Is this different from what everyone was doing with XML back in the day?

  • This is a real “why didn’t I think of that” moment for sure. So many systems I’ve written have profiled with most of the cpu and allocations in the JSON parser, when all it needs is a few fields. But rewriting it all in SAX is just not worth all the trouble.

  • Sounds similar to a technique we're using to dynamically aggregate and transform JSON. We call this package "astjson" as we're doing operations like "walking" through the JSON or "merging" fields at the AST level. We wrote about the topic and how it helped us to improve the performance of our API gateway written in Go, which makes heavy use of JSON aggregations: https://wundergraph.com/blog/astjson_high_performance_json_t...

  • On face it, this sounds kind of like the XML::Twig perl module.

  • Related submission from yesterday:

    https://news.ycombinator.com/item?id=39319746 - JSON Parsing: Intel Sapphire Rapids versus AMD Zen 4 - 40 points and 10 comments

  • I solved this problem with a custom indexed format: https://github.com/7mind/sick

  • > The JSON specification has six structural characters (‘[’, ‘{’, ‘]’, ‘}’, ‘:’, ‘,’) to delimit the location and structure of objects and arrays.

    Wouldn’t a quote “ also be a structural character? It doesn’t actually represent data, it just delimits the beginning and end of a string.

    I get why I’m probably wrong: a string isn’t a structure of chars because that’s not a type in json. The above six are the pieces of the two collections in JSON.

  • Relevant: LEJP - libwebsockets json parser.

    You specify what you're interested in and then the parser calls your callback whenever it reads the part of a large JSON stream that has your key.

    https://libwebsockets.org/lws-api-doc-main/html/md_READMEs_R...

  • Pretty cool!

    This reminds me of oboe.js: https://github.com/jimhigson/oboe.js

  • > The JSON syntax is nearly a strict subset of the popular programming language JavaScript.

    What JSON isn’t valid JS?

  • [dead]

  • 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.