condense.cpp 934 B

12345678910111213141516171819202122232425262728293031
  1. // JSON condenser exmaple
  2. // This example parses JSON text from stdin with validation,
  3. // and re-output the JSON content to stdout without whitespace.
  4. #include "rapidjson/reader.h"
  5. #include "rapidjson/writer.h"
  6. #include "rapidjson/filereadstream.h"
  7. #include "rapidjson/filewritestream.h"
  8. using namespace rapidjson;
  9. int main(int, char*[]) {
  10. // Prepare JSON reader and input stream.
  11. Reader reader;
  12. char readBuffer[65536];
  13. FileReadStream is(stdin, readBuffer, sizeof(readBuffer));
  14. // Prepare JSON writer and output stream.
  15. char writeBuffer[65536];
  16. FileWriteStream os(stdout, writeBuffer, sizeof(writeBuffer));
  17. Writer<FileWriteStream> writer(os);
  18. // JSON reader parse from the input stream and let writer generate the output.
  19. if (!reader.Parse<0>(is, writer)) {
  20. fprintf(stderr, "\nError(%u): %s\n", (unsigned)reader.GetErrorOffset(), reader.GetParseError());
  21. return 1;
  22. }
  23. return 0;
  24. }