title: Is there a simple way to convert json SV or C++ string to HV
body: <p>I have a json string in my C++ class which I converted to SV and returning to my perl module as a scalar. I am parsing this scalar and convert it to json in my perl module.</p>
  
  <p>Instead, I want to convert the json string to a HV or perl hash in my C++ class itself and return it as a perl hash to my perl module. Is there a simple way to do this.</p>
  
  <p>I finally want to convert this json c string to JSON object;</p>
  
  <p>Example:</p>
  
  <p>In my test.cpp I have </p>
  
  <pre><code>std::string json = '{"A":123,"B":"ABC"}';
  </code></pre>
  
  <p>I am converting it to an SV (perl scalar) and sending it to my perl script.</p>
  
  <p>In my test.pl, I am using JSON::XS to encode and decode it to either perl hash or json. </p>
  
  <pre><code>use JSON::XS;
  
  my $perl_hash_or_arrayref  = decode_json $utf8_encoded_json_text;
  my $utf8_encoded_json_text = encode_json $perl_hash_or_arrayref;
  </code></pre>
  
  <p>Actually what I am looking for is to convert the json encoded c++ string to native json and return it to my perl module. I am not sure if this is possible. One solution that i know is parse the json encoded string and convert it to a perl hash and send it to perl module and perl module converts it to native json. But in this case parsing a json encoded c++ string is costly because, my string can be a very long json structure.</p>
  
  <p>but instead of this</p>
  
  <ol>
  <li>Is there a simple way of returning a perl hash($perl_hash_or_arrayref) from my c++ file.</li>
  <li>Or Return json($perl_hash_or_arrayref) from from c++ file.</li>
  </ol>
  
  <p>Thanks in advance!!</p>