Subject: Re: [Boost-bugs] [Boost C++ Libraries] #9721: ptree write_json does not conform to JSON standard
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2017-10-30 22:25:57
#9721: ptree write_json does not conform to JSON standard
--------------------------------------------+----------------------------
Reporter: Mark Pfeifer <Mark_Pfeifer@â¦> | Owner: Sebastian Redl
Type: Bugs | Status: closed
Milestone: To Be Determined | Component: property_tree
Version: Boost 1.55.0 | Severity: Problem
Resolution: invalid | Keywords:
--------------------------------------------+----------------------------
Comment (by rnistuk@â¦):
Here's my fix for numbers:
{{{
#include <string>
#include <boost/regex.hpp>
std::string fix_json_numbers(const std::string &json_str)
{
boost::regex re("\\\"([0-9]+\\.{0,1}[0-9]*)\\\"");
return boost::regex_replace(json_str, re, "$1");
}
}}}
And here's a unit test:
{{{
BOOST_AUTO_TEST_CASE(test_fix_json_str)
{
std::string json_str_in
="{\"cmd\":\"test\",\"data\":{\"integer\":\"283\",\"float\":\"34.433\"}";
std::string json_str_accepted
="{\"cmd\":\"test\",\"data\":{\"integer\":283,\"float\":34.433}";
std::string json_str_actual = fix_json_numbers(json_str_in);
BOOST_CHECK_EQUAL(json_str_accepted, json_str_actual);
}
}}}
NOTE: I've modified the unit test a bit to call the fix_json_numbers
function directly, I have not compiled the unit test.
-- Ticket URL: <https://svn.boost.org/trac10/boost/ticket/9721#comment:8> Boost C++ Libraries <http://www.boost.org/> Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2017-10-30 22:33:18 UTC