2011-11-18 17:01:23 +00:00
|
|
|
// JSON pretty formatting example
|
2011-12-03 11:14:39 +00:00
|
|
|
// This example can only handle UTF-8. For handling other encodings, see prettyauto example.
|
2011-11-18 17:01:23 +00:00
|
|
|
|
|
|
|
#include "rapidjson/reader.h"
|
|
|
|
#include "rapidjson/prettywriter.h"
|
2011-11-21 10:00:33 +00:00
|
|
|
#include "rapidjson/filereadstream.h"
|
|
|
|
#include "rapidjson/filewritestream.h"
|
2011-11-18 17:01:23 +00:00
|
|
|
|
|
|
|
using namespace rapidjson;
|
|
|
|
|
2012-11-16 13:02:05 +00:00
|
|
|
int main(int, char*[]) {
|
2011-11-18 17:01:23 +00:00
|
|
|
// Prepare reader and input stream.
|
|
|
|
Reader reader;
|
2011-11-21 10:00:33 +00:00
|
|
|
char readBuffer[65536];
|
|
|
|
FileReadStream is(stdin, readBuffer, sizeof(readBuffer));
|
2011-11-18 17:01:23 +00:00
|
|
|
|
|
|
|
// Prepare writer and output stream.
|
2011-11-21 10:00:33 +00:00
|
|
|
char writeBuffer[65536];
|
|
|
|
FileWriteStream os(stdout, writeBuffer, sizeof(writeBuffer));
|
|
|
|
PrettyWriter<FileWriteStream> writer(os);
|
2011-11-18 17:01:23 +00:00
|
|
|
|
|
|
|
// JSON reader parse from the input stream and let writer generate the output.
|
2011-11-29 18:39:03 +00:00
|
|
|
if (!reader.Parse<kParseValidateEncodingFlag>(is, writer)) {
|
2011-11-18 17:01:23 +00:00
|
|
|
fprintf(stderr, "\nError(%u): %s\n", (unsigned)reader.GetErrorOffset(), reader.GetParseError());
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|