title: How to check a value for null when using boost json ptree
body: <p>I 'm getting a json response from a server of the following format :</p>
  <pre><code>{&quot;value&quot;: 98.3}  
  </code></pre>
  <p>However there are cases that the response can be :</p>
  <pre><code>{&quot;value&quot;: null}
  </code></pre>
  <p>I have written a C++ program that uses boost json in order to parse this and get the value as float</p>
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;boost/property_tree/ptree.hpp&gt;
  #include &lt;boost/property_tree/json_parser.hpp&gt;
  #include &lt;boost/foreach.hpp&gt;
  
  
  
  using namespace std;
  namespace pt = boost::property_tree;
  
  
  
  int main(int argc, char **argv)
  {
       try
       {
            float valuef;
            pt::ptree root;
            std::stringstream ss;
            string result;
            std::ifstream file(&quot;test.json&quot;);
  
            if (file)
            {
                 ss &lt;&lt; file.rdbuf();
  
                 file.close();
            }
            pt::read_json(ss, root);
            auto value  = root.get&lt;string&gt;(&quot;value&quot;);
            if (value != &quot;null&quot;)
            {
                 valuef = stof(value);
            }
            cout &lt;&lt;&quot;float value is&quot; &lt;&lt; valuef &lt;&lt; endl;
  
       }
  
       catch (std::exception &amp;e)
       {
            string err = e.what();
            cout &lt;&lt; &quot;error is &quot; &lt;&lt; endl
                 &lt;&lt; err &lt;&lt; endl;
       }
  }
  </code></pre>
  <p>So I always check if the value is not equal with the literal &quot;null&quot; because according to this<br />
  <a href="https://stackoverflow.com/questions/21343292/boost-json-with-null-elements">Boost Json with null elements</a>
  outputting nulls is not supported.<br />
  Since the post is 7 years old I was wondering whether the latest boost libraries support something more generic to check for null values ?</p>