condense.cpp 1015 B

1234567891011121314151617181920212223242526272829303132
  1. // JSON condenser example
  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. #include "rapidjson/error/en.h"
  9. using namespace rapidjson;
  10. int main(int, char*[]) {
  11. // Prepare JSON reader and input stream.
  12. Reader reader;
  13. char readBuffer[65536];
  14. FileReadStream is(stdin, readBuffer, sizeof(readBuffer));
  15. // Prepare JSON writer and output stream.
  16. char writeBuffer[65536];
  17. FileWriteStream os(stdout, writeBuffer, sizeof(writeBuffer));
  18. Writer<FileWriteStream> writer(os);
  19. // JSON reader parse from the input stream and let writer generate the output.
  20. if (!reader.Parse(is, writer)) {
  21. fprintf(stderr, "\nError(%u): %s\n", static_cast<unsigned>(reader.GetErrorOffset()), GetParseError_En(reader.GetParseErrorCode()));
  22. return 1;
  23. }
  24. return 0;
  25. }