Boost logo

Boost Users :

Subject: [Boost-users] ptree json parser is not bidirectionnal
From: Sébastien Gallou (sebastien.gallou_at_[hidden])
Date: 2016-03-25 03:28:49


Hi all,

I experience a strange behavior of parsing non-JSON data with JSON parser.
Take this example :

boost::property_tree::ptree m_tree;
> // Non-JSON to ptree using JSON parserstd::istringstream is("1"); // Simple value, non-JSON
> boost::property_tree::json_parser::read_json(is, m_tree); // ==> No exception !
> // ptree back to JSONstd::ostringstream buf;
> boost::property_tree::json_parser::write_json(buf, m_tree, false); // ==> Exception
>
>
Unserializing non-JSON value using JSON parser doesn't raise exception.
If you try to serialize the resulted ptree, you now got an exception.

Is this behavior normal ?

In this case, is there an easy and light mean to check that input value is
JSON formatted (Regex ?) ?

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