Skip to content

Instantly share code, notes, and snippets.

@ivanstojic
Created March 11, 2022 08:04
Show Gist options
  • Save ivanstojic/e072deea3ba411374ed66ead99dbbef8 to your computer and use it in GitHub Desktop.
Save ivanstojic/e072deea3ba411374ed66ead99dbbef8 to your computer and use it in GitHub Desktop.
#include "rapidjson/document.h"
#include "rapidjson/writer.h"
#include "rapidjson/stringbuffer.h"
#include <iostream>
using namespace rapidjson;
int main() {
const char* json = "{\"thing\":-1.1030161663305387}";
Document d;
d.Parse(json);
StringBuffer roundtripBuffer;
Writer<StringBuffer> beforeWriter(roundtripBuffer);
d.Accept(beforeWriter);
Value& s = d["thing"];
double thingVal = -1.1030161663305387;
s.SetDouble(thingVal);
StringBuffer nativeSetBuffer;
Writer<StringBuffer> afterWriter(nativeSetBuffer);
d.Accept(afterWriter);
std::cout << json << std::endl;
std::cout << roundtripBuffer.GetString() << std::endl;
std::cout << nativeSetBuffer.GetString() << std::endl;
return 0;
}
@ivanstojic
Copy link
Author

ivans@cram:~$ g++ simpledom.cpp && ./a.out
{"thing":-1.1030161663305387}
{"thing":-1.103016166330539}
{"thing":-1.1030161663305387}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment