]>
git.proxmox.com Git - ceph.git/blob - ceph/src/rapidjson/example/condense/condense.cpp
1 // JSON condenser example
3 // This example parses JSON text from stdin with validation,
4 // and re-output the JSON content to stdout without whitespace.
6 #include "rapidjson/reader.h"
7 #include "rapidjson/writer.h"
8 #include "rapidjson/filereadstream.h"
9 #include "rapidjson/filewritestream.h"
10 #include "rapidjson/error/en.h"
12 using namespace rapidjson
;
14 int main(int, char*[]) {
15 // Prepare JSON reader and input stream.
17 char readBuffer
[65536];
18 FileReadStream
is(stdin
, readBuffer
, sizeof(readBuffer
));
20 // Prepare JSON writer and output stream.
21 char writeBuffer
[65536];
22 FileWriteStream
os(stdout
, writeBuffer
, sizeof(writeBuffer
));
23 Writer
<FileWriteStream
> writer(os
);
25 // JSON reader parse from the input stream and let writer generate the output.
26 if (!reader
.Parse(is
, writer
)) {
27 fprintf(stderr
, "\nError(%u): %s\n", static_cast<unsigned>(reader
.GetErrorOffset()), GetParseError_En(reader
.GetParseErrorCode()));