[Boost-bugs] [Boost C++ Libraries] #9496: property_tree write_json should output correct types in JSON

Subject: [Boost-bugs] [Boost C++ Libraries] #9496: property_tree write_json should output correct types in JSON
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2013-12-15 12:10:19


#9496: property_tree write_json should output correct types in JSON
-----------------------------------------+---------------------------
 Reporter: Egbert van der Wal <ewal@…> | Owner: cornedbee
     Type: Patches | Status: new
Milestone: To Be Determined | Component: property_tree
  Version: Boost Development Trunk | Severity: Optimization
 Keywords: |
-----------------------------------------+---------------------------
 When using boost::property_tree::write_json it will write all types as
 strings, which is unwanted when wanting to preserve the correct types for
 data.

 - The boolean value is stored as the string "true" or "false",
 - Null is stored as the string "null"
 - Numeric values are also stored as strings
 - Floating point values might end up in their scientific, lossy
 representations

 For my purposes, I need to transfer numeric values (unix timestamps
 represented as double) in their most accurate representation using JSON
 and boolean values to represent correct boolean values without writing
 another text-to-bool converter.

 I will attach a patch that fixes this. For every value in the
 property_tree, it will
 * try to match is with boolean true or false, and write that value
 unquoted to the JSON output
 * try to read it as an integer and if that succeeds, write it unquoted to
 the JSON output
 * try to read it as a double value and if that succeeds, write it unquoted
 with appropriate numeric precision (based on std::numeric_limits) to the
 JSON output
 * try to see if the string matches 'null' and if it does, it will write
 null unquoted to the JSON output
 * if all else fails, write the value as a quoted string to the JSON output

 This will make it a lot easier to interpret the JSON on the receiving and,
 and greatly improve accuracy for double values.

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/9496>
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-02-16 18:50:15 UTC