<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Subhendu Ghosh</title>
    <description>The latest articles on DEV Community by Subhendu Ghosh (@_no_rules_).</description>
    <link>https://dev.to/_no_rules_</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F35494%2Fd35ca545-e59c-4807-86aa-18542984f616.jpg</url>
      <title>DEV Community: Subhendu Ghosh</title>
      <link>https://dev.to/_no_rules_</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/_no_rules_"/>
    <language>en</language>
    <item>
      <title>Understanding RapidJson – Part 2</title>
      <dc:creator>Subhendu Ghosh</dc:creator>
      <pubDate>Wed, 18 Oct 2017 14:38:14 +0000</pubDate>
      <link>https://dev.to/_no_rules_/understanding-rapidjson--part-2-ckg</link>
      <guid>https://dev.to/_no_rules_/understanding-rapidjson--part-2-ckg</guid>
      <description>

&lt;p&gt;Hey guys in my previous &lt;a href="https://dev.to/_no_rules_/understanding-rapidjson-dpi-temp-slug-6318743"&gt;blog&lt;/a&gt; on Rapidjson, alot of people asked for a detailed example in the comments so here is part 2 of  &lt;strong&gt;Understanding Rapidjson&lt;/strong&gt; with a slightly detailed example. I hope this will help you all.&lt;/p&gt;

&lt;p&gt;We will straightaway improve on my last example in the previous blog and modify the &lt;strong&gt;changeDom&lt;/strong&gt; function to add more complex object to the DOM tree.&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;template &amp;lt;typename Document&amp;gt;
void changeDom(Document&amp;amp; d){
Value&amp;amp; node = d["hello"];
node.SetString("c++");
Document subdoc(&amp;amp;d.GetAllocator());
subdoc.SetObject(); // starting the object
Value arr(kArrayType); // the innermost array
Value::AllocatorType allocator;
for (unsigned i = 0; i &amp;lt; 10; i++)
// adding values to array , this function expects an allocator object
arr.PushBack(i, allocator);
// adding the array to its parent object and so on , finally adding it to the parent doc object
subdoc.AddMember("New", Value(kObjectType).Move().AddMember("Numbers",arr, allocator), subdoc.GetAllocator());
// finally adding the sub document to the main doc object
d.AddMember("testing",subdoc, d.GetAllocator());
d["f"] = true;
d["t"].SetBool(false);
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Here we are creating Value objects of type  &lt;strong&gt;kArrayType &lt;/strong&gt; and &lt;strong&gt;kObjectType&lt;/strong&gt; and appending them to their parent node from innermost to outermost.&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Before Manupulation
{
 "hello": "world",
 "t": true,
 "f": false,
 "n": null,
 "i": 123,
 "pi": 3.1416,
 "a": [
 0,
 1,
 2,
 3
 ]
}
After Manupulation
{
 "hello": "c++",
 "t": false,
 "f": true,
 "n": null,
 "i": 123,
 "pi": 3.1416,
 "a": [
    0,
    1,
    2,
    3
  ],
 "testing": {
     "New": {
         "Numbers": [
             0,
             1,
             2,
             3,
             4,
             5,
             6,
             7,
             8,
             9
         ]
     }
 }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The above  &lt;strong&gt;changeDom &lt;/strong&gt; can also be written using &lt;strong&gt;prettywritter&lt;/strong&gt; object as follows:&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;template &amp;lt;typename Document&amp;gt;
void changeDom(Document&amp;amp; d){
Value&amp;amp; node = d["hello"];
node.SetString("c++");
Document subdoc(&amp;amp;d.GetAllocator()); // sub-document
// old school write the json element by element
StringBuffer s;
PrettyWriter&amp;lt;StringBuffer&amp;gt; writer(s);
writer.StartObject();
writer.String("New");
writer.StartObject();
writer.String("Numbers");
writer.StartArray();
for (unsigned i = 0; i &amp;lt; 10; i++)
writer.Uint(i);
writer.EndArray();
writer.EndObject();
writer.EndObject();
subdoc.Parse(s.GetString()); // Parsing the string written to buffer to form a sub DOM

d.AddMember("testing",subdoc, d.GetAllocator()); // Attaching the Sub DOM to the Main DOM object
d["f"] = true;
d["t"].SetBool(false);
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;a href="http://feeds.wordpress.com/1.0/gocomments/subhoworld.wordpress.com/444/"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--okGVR8rN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://feeds.wordpress.com/1.0/comments/subhoworld.wordpress.com/444/" alt=""&gt;&lt;/a&gt; &lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--fyKh9wak--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://pixel.wp.com/b.gif%3Fhost%3Dcodeflu.blog%26blog%3D35076457%26post%3D444%26subd%3Dsubhoworld%26ref%3D%26feed%3D1" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fyKh9wak--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://pixel.wp.com/b.gif%3Fhost%3Dcodeflu.blog%26blog%3D35076457%26post%3D444%26subd%3Dsubhoworld%26ref%3D%26feed%3D1" alt=""&gt;&lt;/a&gt;&lt;/p&gt;


</description>
      <category>c</category>
      <category>general</category>
      <category>json</category>
      <category>rapidjson</category>
    </item>
    <item>
      <title>Glow LEDs with Google Home</title>
      <dc:creator>Subhendu Ghosh</dc:creator>
      <pubDate>Fri, 28 Apr 2017 20:47:47 +0000</pubDate>
      <link>https://dev.to/_no_rules_/glow-leds-with-google-home-9mh</link>
      <guid>https://dev.to/_no_rules_/glow-leds-with-google-home-9mh</guid>
      <description>&lt;p&gt;Recently I tried experimenting with Google Home, trying to voice control LEDs. Majorly the whole thing can be split into two parts,&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;A custom command that makes a web POST request to fetch the result.&lt;/li&gt;
&lt;li&gt;A simple Flask app that can receive post request with parameters and glow some LEDs based on the POST request data.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;For the part one, the custom commands were possible thanks to &lt;a href="https://developers.google.com/actions/develop/conversation" rel="noopener noreferrer"&gt;Google Actions Apis&lt;/a&gt;.  I used &lt;a href="https://api.ai/" rel="noopener noreferrer"&gt;API.AI&lt;/a&gt; for my purpose since they had good documentation. I wont go into detail explaining the form fields in &lt;a href="https://api.ai" rel="noopener noreferrer"&gt;Api.ai&lt;/a&gt;, they have done a good job with documentation and explaining part, I will just share my configurations screenshot for your quick reference and understanding. In Api.ai the conversations are broken into &lt;strong&gt;intents.&lt;/strong&gt;   I used one intent (Default Welcome Intent) and a followup intent (Default Welcome Intent – custom) for my application.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsubhoworld.files.wordpress.com%2F2017%2F04%2Ftop-intents.png%3Fw%3D660" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsubhoworld.files.wordpress.com%2F2017%2F04%2Ftop-intents.png%3Fw%3D660" alt="top-intents"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Heres my first intent which basically greets the user and asks for a LED colour when the custom command &lt;strong&gt;“glow LEDs”&lt;/strong&gt; is activated.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsubhoworld.files.wordpress.com%2F2017%2F04%2Fintent1.png%3Fw%3D660" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsubhoworld.files.wordpress.com%2F2017%2F04%2Fintent1.png%3Fw%3D660" alt="intent1"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see the &lt;strong&gt;User says&lt;/strong&gt; is what defines my command , you can add multiple statements in which you want to activate the command. The &lt;strong&gt;Action&lt;/strong&gt; and &lt;strong&gt;Contexts&lt;/strong&gt; is set when you create a followup Intent. &lt;strong&gt;Text response&lt;/strong&gt; is the part which your Google Home will use as response.&lt;/p&gt;

&lt;p&gt;Next is the Followup Intent which basically takes the User response as input context (which is handled automatically when you create the followup intent) and looks for required parameters and tries to process the request.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsubhoworld.files.wordpress.com%2F2017%2F04%2Fuser_interaction.png%3Fw%3D660" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsubhoworld.files.wordpress.com%2F2017%2F04%2Fuser_interaction.png%3Fw%3D660" alt="user_interaction"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here the expected &lt;strong&gt;User says &lt;/strong&gt; would be a colour (red, blue, green) is what I allowed. In Api.ai you can use their ML to process the speech and find your needed parameters and values. I needed colours hence used &lt;strong&gt;&lt;a class="mentioned-user" href="https://dev.to/sys"&gt;@sys&lt;/a&gt;.color. &lt;/strong&gt; Their are other entities like &lt;a class="mentioned-user" href="https://dev.to/sys"&gt;@sys&lt;/a&gt;.address or &lt;a class="mentioned-user" href="https://dev.to/sys"&gt;@sys&lt;/a&gt;.flight etc. If these entities don’t serve your purpose then you might want to go vanilla and process the speech on your web-api end. The later part of the Followup Intent is a bit different, we are fulfilling the user request via web-hook here. Here the &lt;strong&gt;Response &lt;/strong&gt; is the fallback response incase the web request fails, the success response is received from web-hook response body.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsubhoworld.files.wordpress.com%2F2017%2F04%2Fhome-response.png%3Fw%3D660" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsubhoworld.files.wordpress.com%2F2017%2F04%2Fhome-response.png%3Fw%3D660" alt="home-response"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The fulfilment option won’t be activated until you add your webhook in the &lt;strong&gt;Fulfillment&lt;/strong&gt; section. Thats all for the part one. Also you can use &lt;a href="https://developers.google.com/actions/tools/web-simulator" rel="noopener noreferrer"&gt;Google Web Simulator&lt;/a&gt; to test your application On the Go.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsubhoworld.files.wordpress.com%2F2017%2F04%2Fwebhook.png%3Fw%3D677%26h%3D482" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsubhoworld.files.wordpress.com%2F2017%2F04%2Fwebhook.png%3Fw%3D677%26h%3D482" alt="webhook.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In part two , I used a Raspberry Pi, 3 LEDs (red, blue, green) , a 1K ohm resistor some wires, a breadboard(optional)  and a T-cobbler Board(optional). Now, we will write a flask application that will accept a post request and turn on the required GPIO pin output high/low.&lt;/p&gt;

&lt;p&gt;You can check with the request and response structure you need from the Api.ai docs. Next, this application receives the calls from api.ai webhook and it triggers the targeted LED depending on the &lt;strong&gt;resolvedQuery.&lt;/strong&gt; The above code was written so that I can test locally with get requests too. I used &lt;a href="http://pagekite.net" rel="noopener noreferrer"&gt;pagekite.net&lt;/a&gt; to tunnel and expose my flask application to the external world. Following is the circuit diagram for the connections.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsubhoworld.files.wordpress.com%2F2017%2F04%2Fcircuit.png%3Fw%3D1027%26h%3D553" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsubhoworld.files.wordpress.com%2F2017%2F04%2Fcircuit.png%3Fw%3D1027%26h%3D553" alt="circuit"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Following is the Result,&lt;/p&gt;

&lt;p&gt;Some more Reads:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://arstechnica.com/gadgets/2016/12/google-assistant-api-launches-today-so-we-tested-some-custom-voice-commands/" rel="noopener noreferrer"&gt;https://arstechnica.com/gadgets/2016/12/google-assistant-api-launches-today-so-we-tested-some-custom-voice-commands/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.api.ai/docs/actions-on-google-integration" rel="noopener noreferrer"&gt;https://docs.api.ai/docs/actions-on-google-integration&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developers.google.com/actions/develop/conversation" rel="noopener noreferrer"&gt;https://developers.google.com/actions/develop/conversation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developers.google.com/actions/develop/apiai/tutorials/getting-started" rel="noopener noreferrer"&gt;https://developers.google.com/actions/develop/apiai/tutorials/getting-started&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developers.google.com/actions/samples/" rel="noopener noreferrer"&gt;https://developers.google.com/actions/samples/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.api.ai/docs/webhook" rel="noopener noreferrer"&gt;https://docs.api.ai/docs/webhook&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.api.ai/docs/concept-intents#user-says" rel="noopener noreferrer"&gt;https://docs.api.ai/docs/concept-intents#user-says&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt; &lt;/p&gt;

&lt;p&gt;&lt;a href="http://feeds.wordpress.com/1.0/gocomments/subhoworld.wordpress.com/297/" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/http%3A%2F%2Ffeeds.wordpress.com%2F1.0%2Fcomments%2Fsubhoworld.wordpress.com%2F297%2F"&gt;&lt;/a&gt; &lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpixel.wp.com%2Fb.gif%3Fhost%3Dcodeflu.blog%26blog%3D35076457%26post%3D297%26subd%3Dsubhoworld%26ref%3D%26feed%3D1" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpixel.wp.com%2Fb.gif%3Fhost%3Dcodeflu.blog%26blog%3D35076457%26post%3D297%26subd%3Dsubhoworld%26ref%3D%26feed%3D1"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>iot</category>
      <category>python</category>
      <category>glowleds</category>
      <category>googlehome</category>
    </item>
    <item>
      <title>Understanding RapidJson</title>
      <dc:creator>Subhendu Ghosh</dc:creator>
      <pubDate>Thu, 26 Feb 2015 12:30:34 +0000</pubDate>
      <link>https://dev.to/_no_rules_/understanding-rapidjson-77p</link>
      <guid>https://dev.to/_no_rules_/understanding-rapidjson-77p</guid>
      <description>&lt;p&gt;With new technologies softwares need to evolve and adapt. My new task is to make cppagent generate output in Json (JavaScript Object Notation) format. Last week i spent sometime to try out different libraries and finally settled on using &lt;a href="https://github.com/miloyip/rapidjson" rel="noopener noreferrer"&gt;Rapidjson&lt;/a&gt;. &lt;strong&gt; &lt;/strong&gt; Rapidjson is a json manipulation library  for c++ which is fast, simple and has compatibility with different c++ compilers in different platforms. In this post we will be looking at example codes to generate, parse and manipulate &lt;strong&gt;json &lt;/strong&gt; data. For people who want to use this library i would highly recommend them to play with and understand the &lt;a href="https://github.com/miloyip/rapidjson/tree/master/example" rel="noopener noreferrer"&gt;example&lt;/a&gt; codes first.&lt;/p&gt;

&lt;p&gt;First we will write a simple program to write a sample json as below (the same &lt;a href="https://github.com/miloyip/rapidjson/blob/master/example/simplewriter/simplewriter.cpp" rel="noopener noreferrer"&gt;simplewriter.cpp&lt;/a&gt; as in example) :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
    "hello" : "world" ,
    "t" : true ,
    "f" : false ,
    "i" : 123 ,
    "pi" : 3.1416 ,
    "a": [
        0,
        1,
        2,
        3
    ]
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To generate a Json output you need:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;a &lt;strong&gt;StringBuffer&lt;/strong&gt; object, a buffer object to write the Json output.&lt;/li&gt;
&lt;li&gt;a  &lt;strong&gt;Writer &lt;/strong&gt; object to write Json to the buffer. Here i have used &lt;strong&gt;PrettyWriter&lt;/strong&gt; object to write human-readable and properly indented json output.&lt;/li&gt;
&lt;li&gt;functions &lt;strong&gt;StartObject/EndObject&lt;/strong&gt; to start and close a json object parenthesis “ &lt;strong&gt;{&lt;/strong&gt; ” and  “ &lt;strong&gt;}&lt;/strong&gt; ” respectively.&lt;/li&gt;
&lt;li&gt;functions &lt;strong&gt;StartArray/EndArray&lt;/strong&gt; to start and end a json array object i.e “&lt;strong&gt;[&lt;/strong&gt;” and “&lt;strong&gt;]&lt;/strong&gt;“.&lt;/li&gt;
&lt;li&gt;functions String(), Uint(), Bool(), Null() , Double()  are called on &lt;strong&gt;writer&lt;/strong&gt; object to write string, unsigned integer, boolean, null, floating point numbers respectively.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#include "rapidjson/stringbuffer.h"
#include "rapidjson/prettywriter.h"
#include &amp;lt;iostream&amp;gt;

using namespace rapidjson;
using namespace std;

template &amp;lt;typename Writer&amp;gt;
void display(Writer&amp;amp; writer );

int main() {
 StringBuffer s; 
 PrettyWriter&amp;lt;StringBuffer&amp;gt; writer(s);
 display(writer);
 cout &amp;lt;&amp;lt; s.GetString() &amp;lt;&amp;lt; endl; // GetString() stringify the Json
 }

template &amp;lt;typename Writer&amp;gt;
void display(Writer&amp;amp; writer){
 writer.StartObject(); // write "{"
 writer.String("hello"); // write string "hello"
 writer.String("world");
 writer.String("t"); 
 writer.Bool(true); // write boolean value true
 writer.String("f");
 writer.Bool(false);
 writer.String("n");
 writer.Null(); // write null
 writer.String("i");
 writer.Uint(123); // write unsigned integer value
 writer.String("pi");
 writer.Double(3.1416); // write floating point numbers
 writer.String("a");
 writer.StartArray(); // write "["
 for (unsigned i = 0; i &amp;lt; 4; i++)
 writer.Uint(i);
 writer.EndArray(); // End Array "]"
 writer.EndObject(); // end Object "}"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next we will manipulate the Json document and change the value for key “Hello” to “C++” ,&lt;/p&gt;

&lt;p&gt;To manipulate:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;first you need to parse your json data into a  &lt;strong&gt;Document &lt;/strong&gt; object.&lt;/li&gt;
&lt;li&gt;Next you may use a &lt;strong&gt;Value &lt;/strong&gt; reference to the value of the desired node/key or you can directly access them as &lt;strong&gt;doc_object[â€˜key’] &lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Finally you need to call the &lt;strong&gt;Accept&lt;/strong&gt; method passing the &lt;strong&gt;Writer&lt;/strong&gt; object to write the document to the StringBuffer object.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Below function changes the keywords for “hello” , “t”, “f” to “c++” , false , true respectively.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;template &amp;lt;typename Document&amp;gt;
void changeDom(Document&amp;amp; d){
// any of methods shown below can be used to change the document
Value&amp;amp; node = d["hello"]; // using a reference
node.SetString("c++"); // call SetString() on the reference
d["f"] = true; // access directly and change
d["t"].SetBool(false); // best way
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now to put it all together:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Before Manupulation
{
     "hello": "world",
     "t": true,
     "f": false,
     "n": null,
     "i": 123,
     "pi": 3.1416,
     "a": [
        0,
        1,
        2,
        3
     ]
}
After Manupulation
{
     "hello": "c++",
     "t": false,
     "f": true,
     "n": null,
     "i": 123,
     "pi": 3.1416,
     "a": [
        0,
        1,
        2,
        3
      ]
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The final code to display the above output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#include "rapidjson/stringbuffer.h"
#include "rapidjson/prettywriter.h"
#include "rapidjson/document.h"
#include &amp;lt;iostream&amp;gt;

using namespace rapidjson;
using namespace std;

template &amp;lt;typename Writer&amp;gt; 
void display(Writer&amp;amp; writer);

template &amp;lt;typename Document&amp;gt;
void changeDom(Document&amp;amp; d);

int main() {
 StringBuffer s;
 Document d;
 PrettyWriter&amp;lt;StringBuffer&amp;gt; writer(s);
 display(writer);
 cout &amp;lt;&amp;lt; "Before Manupulation\n" &amp;lt;&amp;lt; s.GetString() &amp;lt;&amp;lt; endl ;
 d.Parse(s.GetString());
 changeDom(d);
 s.Clear(); // clear the buffer to prepare for a new json document
 writer.Reset(s); // resetting writer for a fresh json doc
 d.Accept(writer); // writing parsed document to buffer
 cout &amp;lt;&amp;lt; "After Manupulation\n" &amp;lt;&amp;lt; s.GetString() &amp;lt;&amp;lt; endl;
 }

template &amp;lt;typename Document&amp;gt;
void changeDom(Document&amp;amp; d){
Value&amp;amp; node = d["hello"];
node.SetString("c++");
d["f"] = true;
d["t"].SetBool(false);
}

template &amp;lt;typename Writer&amp;gt;
void display(Writer&amp;amp; writer){
 writer.StartObject();
 writer.String("hello");
 writer.String("world");
 writer.String("t");
 writer.Bool(true);
 writer.String("f");
 writer.Bool(false);
 writer.String("n");
 writer.Null();
 writer.String("i");
 writer.Uint(123);
 writer.String("pi");
 writer.Double(3.1416);
 writer.String("a");
 writer.StartArray();
 for (unsigned i = 0; i &amp;lt; 4; i++)
 writer.Uint(i);
 writer.EndArray();
 writer.EndObject();
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="http://feeds.wordpress.com/1.0/gocomments/subhoworld.wordpress.com/251/" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/http%3A%2F%2Ffeeds.wordpress.com%2F1.0%2Fcomments%2Fsubhoworld.wordpress.com%2F251%2F"&gt;&lt;/a&gt; &lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpixel.wp.com%2Fb.gif%3Fhost%3Dcodeflu.blog%26blog%3D35076457%26post%3D251%26subd%3Dsubhoworld%26ref%3D%26feed%3D1" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpixel.wp.com%2Fb.gif%3Fhost%3Dcodeflu.blog%26blog%3D35076457%26post%3D251%26subd%3Dsubhoworld%26ref%3D%26feed%3D1"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>c</category>
      <category>general</category>
      <category>json</category>
      <category>rapidjson</category>
    </item>
  </channel>
</rss>
