Added a "strict JSON" mode to the text generator and compiler

This will add quotes around field names, as required by the official
standard. By default it will leave quotes out, as it is more readable,
more compact, and is accepted by almost all JSON parsers.
The -S switch to flatc turns on strict mode.

As per rfc 7159.

Change-Id: Ibabe9c8162c47339d00ec581d18721a2ba40c6d0
Tested: on Windows.
This commit is contained in:
Wouter van Oortmerssen
2014-07-08 16:35:14 -07:00
parent 9140144d51
commit 7fcbe723fc
11 changed files with 94 additions and 50 deletions

View File

@@ -46,7 +46,8 @@ int main(int /*argc*/, const char * /*argv*/[]) {
// to ensure it is correct, we now generate text back from the binary,
// and compare the two:
std::string jsongen;
GenerateText(parser, parser.builder_.GetBufferPointer(), 2, &jsongen);
GenerateText(parser, parser.builder_.GetBufferPointer(),
flatbuffers::GeneratorOptions(), &jsongen);
if (jsongen != jsonfile) {
printf("%s----------------\n%s", jsongen.c_str(), jsonfile.c_str());