Search code examples
c++rapidjson

RapidJSON: how to parse first-level only?


I'm working with RapidJSON to parse a few configuration files for my game (material definitions, components, etc). However, i'm curious if it's possible to configure RapidJSON to parse only the first level in the JSON document. Imagine this:

{
  "foo": "bar",
  "bar": "foo",
  "nested": {
    "foo": "bar"
  }
}

foo is the string bar, bar is the string foo, and nested is the string {"foo": "bar"}

Is this possible? I have several nested documents that i don't need to parse and i don't want RapidJSON to waste time on them.


Solution

  • No. RapidJSON currently not support this.

    I think it will not help alot as it still need to do lexical analysis for the parts you want to skip.

    However, you may filter the events via custom event handlers as in this example.

    By the way, as a game developer as well, I think normal configuration files will not be too big. The parsing speed of RapidJSON should be much lower than I/O time. If you need just parts of JSON, you may preprocess it to store the data separately.