Search code examples
c++flatbuffers

How can I get the correct json in FlatBuffers?


I successfully parsed the data,but then are not correct json data.How can I get the correct json in FlatBuffers? My code:

auto result = GenerateText(parser, in, &json_data);
flatbuffers::SaveFile("test.json",json_data.c_str(), json_data.size(), true);

test.json`s content:

{
  account: "0520-1",
  passwd: "",
  device: "test",
  token: "11aasasdfasdf"
}

It cannot be parsed correctly by JSON. Thanks !!!


Solution

  • You need to enable the strict_json option on the Parser, otherwise you don't get the quoted field names that JSON requires:

    auto options = IDLOptions();
    options.strict_json = true;
    auto parser = Parser(options);