Boost logo

Boost Users :

Subject: [Boost-users] [property_tree] Json parser with invalid JSON string
From: Sébastien Gallou (sebastien.gallou_at_[hidden])
Date: 2016-04-13 10:36:59


Hi all,

I experience a strange behavior of parsing non-JSON data with JSON parser.
I can create a property_tree from a simple non-JSON string, without
exception. And serializing back the result throws :

boost::property_tree::ptree m_tree;
// Non-JSON to ptree using JSON parser
std::istringstream is("1"); // Simple value, non-JSON
boost::property_tree::json_parser::read_json(is, m_tree); // ==> No
exception, I now have a valid ptree object.

// ptree back to JSON
std::ostringstream buf;
boost::property_tree::json_parser::write_json(buf, m_tree, false); // ==>
Exception

How can I filter input values that will not be serializable later (= verify
that input value is well JSON formatted) ?

Thanks for your help,
S. Gallou



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net