Resolved warnings on GCC Issue #127
Fix for platform issue with vs2017:
- Renamed label
minustominus_signinjson_parser.hpp
Enhancements:
- New classes
byte_stringandbyte_string_view, to augment support for cbor byte strings injsonvalues
Changes:
-
template <class CharT> json_traits<CharT>replaced withsorted_policy -
template <class CharT> o_json_traits<CharT>replaced withpreserve_order_policy -
The return type for the json::get_with_default function overload for
const char*has been changed fromconst char*tojson::string_view_type, which is assignable tostd::string. -
New functions
byte_string_valueanddo_byte_string_valuehave been added tobasic_json_input_handlerandbasic_json_output_handler -
json::is<const char*>() and json::as<const char*>() specializations (supported but never documented) have been deprecated
-
In android specific
string_to_double,strtod_lchanged tostrtold_l
Enhancements:
-
The
jsonclass and thedecode_cborandencode_cborfunctions now support byte strings Ajsonbyte string value will, when serialized to JSON, be converted to a base64url string. -
version.hppadded toincludedirectory
Bug fixes:
- Fixed issue with jsonpatch::diff (fix contributed by Alexander (rog13))
Enhancements:
- New class
cbor_viewfor accessing packedcborvalues. Acbor_viewsatisfies the requirements forjsonpointer::get.
jsonpointer::eraserenamed tojsonpointer::remove, old name deprecated
-
JSON Pointer implementation
-
JSON Patch implementation, includes patch and diff
-
json::insertfunction for array that inserts values from range [first, last) before pos.
Bug fixes
- Fixed issue with serialization of json array of objects to csv file
-
The member function name
json::dump_bodyhas been deprecated and replaced withjson::dump_fragment. -
The non member function name
dump_bodyhas been deprecated and replaced withdump_fragment. -
The class name
rename_name_filterhas been deprecated and replaced withrename_object_member_filter. -
In the documentation and examples, the existing function
json::insert_or_assignis now used instead of the still-supportedjson::set. The reason is thatinsert_or_assignfollows the naming convention of the C++ standard library.
-
The recently introduced class
json_stream_traitshas been renamed toserialization_traits -
Removed template parameter
CharTfrom classbasic_parsing_contextand renamed it toparsing_context -
Removed template parameter
CharTfrom classbasic_parse_error_handlerand renamed it toparse_error_handler
New features
- Added
jsonfunctionspush_backandinsertfor appending values to the end of ajsonarray and inserting values at a specifed position
Rationale: While these functions provide the same functionality as the existing
json::add function, they have the advantage of following the naming conventions
of the C++ library, and have been given prominence in the examples and documentation
(add is still supported.)
New features
-
cbor extension supports encoding to and decoding from the cbor binary serialization format.
-
json_type_traitssupportsstd::valarray
Documentation
- Documentation is now in the repository itself. Please see the documentation link in the README.md file
Changed
- Removed
CharTtemplate parameter fromjson_stream_traits
Changes
-
Visual Studio 2013 is no longer supported (jsonpath uses string initilizer lists)
-
json_input_handleroverloaded functions value(value,context)have been deprecated. Instead usestring_value(value,context),integer_value(value,context),uinteger_value(value,context),double_value(value,precision,context),bool_value(value,context)andnull_value(context)` -
json_output_handleroverloaded functions value(value)have been deprecated. Instead usestring_value(value),integer_value(value),uinteger_value(value),double_value(value,precision=0),bool_value(value)andnull_value(context)` -
For consistency, the names
jsoncons_ext/msgpack/message_pack.hpp,encode_message_packanddecode_message_packhave been deprecated and replaced withjsoncons_ext/msgpack/msgpack.hpp,encode_msgpackanddecode_msg_pack
Bug fixes
-
Fixed operator== throws when comparing a string against an empty object
-
Fixed jsonpath issue with array 'length' (a.length worked but not a['length'])
-
msgpackextension uses intrinsics for determing whether to swap bytes
New features
-
Stream supported C++ values directly to JSON output, governed by
json_stream_traits -
json::is() and json::as() accept template packs, which they forward to the
json_type_traitsisandasfunctions. This allows user definedjson_type_traitsimplementations to resolve, for instance, a name into a C++ object looked up from a registry. See Type Extensibility, Example 2. -
jsonpath
json_querynow supports returning normalized paths (with optionalreturn_type::pathparameter) -
New jsonpath
maxandminaggregate functions over numeric values -
New
json::mergefunction that inserts another json object's key-value pairs into a json object, if they don't already exist. -
New
json::merge_or_updatefunction that inserts another json object's key-value pairs into a json object, or assigns them if they already exist.
-
json_type_traitssupportsstd::pair(convert to/from json array of size 2) -
parse_streamrenamed toparse(backwards compatible) -
kvp_typerenamed tokey_value_pair_type(backwards compatible) -
The
_jsonand_ojsonliteral operators have been moved to the namespacejsoncons::literals. Access to these literals now requires
using namespace jsoncons::literals; Rationale: avoid name clashes with other json libraries
-
The name
owjsonhas been deprecated (still works) and changed towojson. Rationale: naming consistency -
Added json array functions
emplace_backandemplace, and json object functionstry_emplaceandinsert_or_assign, which are analagous to the standard library vector and map functions.
Bug fix
- A bug was introduced in 0.99.7 causing the values of existing object members to not be changed wiht set or assignment operations. This has been fixed.
Change
- jsoncons_ext/binary changed to jsoncons_ext/msgpack
- namespace jsoncons::binary changed to jsoncons::msgpack
- Workarounds in unicode_traits and jsonpath to maintain support for vs2013
- Added
mapping_type::n_rows,mapping_type::n_objects, andmapping_type::m_columnsoptions for csv to json
Bug fixes
- Issues with precedence in JsonPath filter evaluations have been fixed
- An issue with (a - expression) in JsonPath filter evaluations has been fixed
New feature
- The new binary extension supports encoding to and decoding from the MessagePack binary serialization format.
- An extension to JsonPath to allow filter expressions over a single object.
- Added support for
*and/operators to jsonpath filter - literal operators _json and _ojson have been introduced
Non-breaking changes
- The
jsonwritefunctions have been renamed todump. The old names have been deprecated but still work. - Support for stateful allocators
- json function object_range() now returns a pair of RandomAccessIterator (previously BidirectionalIterator)
- json operator [size_t i] applied to a json object now returns the ith object (previously threw)
Breaking change (if you've implemented your own input and output handlers)
In basic_json_input_handler, the virtual functions
virtual void do_name(const CharT* value, size_t length,
const basic_parsing_context<CharT>& context)
virtual void do_string_value(const CharT* value, size_t length,
const basic_parsing_context<CharT>& context)have been changed to
virtual void do_name(string_view_type val,
const basic_parsing_context<CharT>& context)
virtual void do_string_value(string_view_type val,
const basic_parsing_context<CharT>& context) In basic_json_output_handler, the virtual functions
virtual void do_name(const CharT* value, size_t length)
virtual void do_string_value(const CharT* value, size_t length) have been changed to
virtual void do_name(string_view_type val)
virtual void do_string_value(string_view_type val)Removed features:
- The jsonx extension has been removed
- Validations added to utf8 and utf16 string parsing to pass all JSONTestSuite tests
- The name
json_encoderintroduced in 0.99.4 has been changed tojson_decoder. Rationale: consistencty with common usage (encoding and serialization, decoding and deserialization)
Fixes Issue #101, In json.hpp, line 3376 change "char__type" to "char_type" Fixes Issue #102, include cstring and json_error_category.hpp in json.hpp
Changes
- The deprecated class
json::anyhas been removed. - The jsoncons
boostextension has been removed. That extension contained a samplejson_type_traitsspecialization forboost::gregorian::date, which may still be found in the "Type Extensibility" tutorial. - The member
json_type_traitsmember functionassignhas been removed and replaced byto_json. if you have implemented your own type specializations, you will also have to change yourassignfunction toto_json. json_type_traitsspecializations no longer require theis_assignabledata member
Non-breaking name changes
- The names
json_deserializer,ojson_deserializer,wjson_deserializer,owjson_deserializerhave been deprecated (they still work) and replaced byjson_encoder<json>,json_encoder<ojson>,json_encoder<wjson>andjson_encoder<owjson>. - The name
output_formathas been deprecated (still works) and renamed toserialization_options. - The name
wojsonhas been deprecated (still works) and renamed toowjson. - The
json_filtermember functioninput_handlerhas been deprecated (still works) and renamed todownstream_handler. - The name
elementshas been deprecated (still works) and renamed toowjson. - The
jsonmember functionmembers()has been deprecated (still works) and renamed toobject_range(). - The
jsonmember functionelements()has been deprecated (still works) and renamed toarray_range(). - The
jsonmember_type functionname()has been deprecated (still works) and renamed tokey(). Rationale: consistency with more general underlying storage classes.
New features
json_filterinstances can be passed to functions that take ajson_output_handlerargument (previously only ajson_input_handlerargument)- New
jsonpathfunctionjson_replacethat searches for all values that match a JsonPath expression and replaces them with a specified value. jsonclass has new methodhas_key(), which returnstrueif ajsonvalue is an object and has a member with that key- New filter class
rename_nameallows search and replace of JSON object names
Changes
The json initializer-list constructor has been removed, it gives inconsistent results when an initializer has zero elements, or one element of the type being initialized (json). Please replace
json j = {1,2,3} with json j = json::array{1,2,3}, and
json j = {{1,2,3},{4,5,6}} with json j = json::array{json::array{1,2,3},json::array{4,5,6}}
- Initializer-list constructors are now supported in
json::objectas well asjson::array, e.g.
json j = json::object{{"first",1},{"second",json::array{1,2,3}}};-
json::any has been deprecated and will be removed in the future
-
The json method
to_streamhas been renamed towrite, the old name is still supported. -
output_formatobject_array_block_option,array_array_block_optionfunctions have been deprecated and replaced byobject_array_split_lines,array_array_split_linesfunctions.
Enhancements
-
A new method
get_with_default, with return type that of the default, has been added tojson -
A new template parameter,
JsonTraits, has been added to thebasic_jsonclass template. -
New instantiations of
basic_json,ojsonandwojson, have been added for users who wish to preserve the alphabetical sort of parsed json text and to insert new members in arbitrary name order. -
Added support for
jsonis<T>,as<T>, constructor, and assignment operator for any sequence container (std::array,std::vector,std::deque,std::forward_list,std::list) whose values are assignable to JSON types (e.g., ints, doubles, bools, strings, STL containers of same) and for associative containers (std::set,std::multiset,std::unordered_set,std::unordered_multiset.) -
Added static method
null()tojsonclass to return null value -
A new extension jsonx that supports serializing JSON values to JSONx (XML)
-
json parser will skip
bomin input if present
Fixes:
-
Fixes to the
jsonpathextension, including the union operator and applying index operations to string values -
Fixes to remove warnings and issues reported by VS2015 with 4-th warnings level, PVS-Studio static analyzer tool, and UBSAN.
-
Included workaround for a C++11 issue in GCC 4.8, contributed by Alex Merry
-
Fixed operator== so that json() == json(json::object())
-
Fixed issue with
jsonassignment to initializer list -
Fixed issue with assignment to empty json object with multiple keys, e.g.
json val; val["key1"]["key2"] = 1;
- Fix to json_filter class
- Fix to readme_examples
- Fixes to deprecated json parse functions (deprecated, but still supposed to work)
- The Visual C++ specific implementation for reading floating point numbers should have freed a
_locale_tobject, fixed - Added
json_type_traitsspecialization to support assignment from non-const strings - When parsing fractional numbers in text, floating point number precision is retained, and made available to serialization to preserve round-trip. The default output precision has been changed from 15 to 16.
- Added json
std::initializer_listconstructor for constructing arrays - The deprecated json member constants null, an_object, and an_array have been removed
- Microsoft VC++ versions earlier than 2013 are no longer supported
- Fixes issues with compilation with clang
New features
- Supports Stefan Goessner's JsonPath.
- json member function
findadded - json member function
countadded - json array range accessor
elements()added, which supports range-based for loops over json arrays, and replacesbegin_elementsandend_elements - json object range accessor
members()added, which supports range-based for loops over json objects, and replacesbegin_membersandend_members - New version of json
addmember function that takes a parameterarray_iterator - json member function
shrink_to_fitadded
API Changes
-
The json internal representation of signed and unsigned integers has been changed from
long longandunsigned long longtoint64_tanduint64_t. This should not impact you unless you've implemented your ownjson_input_handlerorjson_output_handler, in which case you'll need to change yourjson_input_handlerfunction signaturesvoid do_longlong_value(long long value, const basic_parsing_context& context) override void do_ulonglong_integer_value(unsigned long long value, const basic_parsing_context& context) override
to
void do_integer_value(int64_t value, const basic_parsing_context<Char>& context) override
void do_uinteger_value(uint64_t value, const basic_parsing_context<Char>& context) override
and your json_output_handler function signatures from
void do_longlong_value(long long value) override
void do_ulonglong_integer_value(unsigned long long value) override
to
void do_integer_value(int64_t value) override
void do_uinteger_value(uint64_t value) override
output_formatdrops support forfloatfieldproperty
Non-beaking API Changes
- remove_range has been deprecated, use erase(array_iterator first, array_iterator last) instead
- remove has been deprecated, use erase(const std::string& name ) instead
json::parse_stringhas been renamed tojson::parse,parse_stringis deprecated but still worksjson member functionis_emptyhas been renamed toempty,is_empty` is deprecated but still works. Rationale: consistency with C++ containers- json member functions
begin_elementsandend_elementshave been deprecated, instead useelements().begin()andelements.end() - json member functions
begin_membersandend_membershave been deprecated, instead usemembers().begin()andmembers.end() - json member function
has_memberhas been deprecated, instead usecount. Rationale: consistency with C++ containers - json member function
remove_memberhas been deprecated, instead useremove. Rationale: only member function left with _element or _member suffix - json_parse_exception renamed to parse_error, json_parse_exception typedef to parse_error
- json::parse(std::istream& is) renamed to json::parse_stream. json::parse(std::istream is) is deprecated but still works.
jsonconstructor is now templated, so constructors now accept extended types- Following RFC7159,
json_parsernow accepts any JSON value, removing the constraint that it be an object or array. - The member
json_type_traitsmember functionsis,as, andassignhave been changed to static functions. if you have implemented your own type specializations, you will also have to change youris,asandassignfunctions to be static. - Removed json deprecated functions
custom_data,set_custom_data,add_custom_data json_readermember functionmax_depthhas been renamed tomax_nesting_depth, the former name is still supported.jsonmember functionresize_arrayhas been renamed toresize, the former name is still supported.
jsoncons supports alternative ways for constructing null, object, and array values.
null:
json a = jsoncons::null_type(); // Using type constructor
json b = json::null_type(); // Using alias
json c(json::null); // From static data member prototype
object:
json a(); // Default is empty object
json b = json::object(); // Using type constructor
json c(json::an_object); // From static data member prototype
array:
json a = json::array(); // Using type constructor
json b = json::make_array(); // Using factory method
json c(json::an_array); // From static data member prototype
Since C++ has possible order issues with static data members, the jsoncons examples and documentation have been changed to consistently use the other ways, and json::null, json::an_object and json::an_array have been, while still usable, deprecated.
- Enhances parser for CSV files that outputs JSON, see example below.
- Adds
get_resultmember function tojson_deserializer, which returns the json valuevstored in ajson_deserializerasstd::move(v). Theroot()member function has been deprecated but is still supported. - Adds
is_validmember function tojson_deserializer - Enhances json::any class, adds type checks when casting back to original value
- Fixes some warning messages
Bug fixes:
- Fixes the noexcept specification (required for Visual Studio 2015 and later.) Fix contributed by Rupert Steel.
- Fixes bug with proxy operator== when comparing object member values, such as in val["field"] == json("abc")
Enhancements:
-
Refines error codes and improves error messages
-
Renames
json_readermethodreadtoread_next, reflecting the fact that it supports reading a sequence of JSON texts from a stream. The former name is deprecated but still works. -
Adds
json_readermethodcheck_donethat throws if there are unconsumed non-whitespace characters after one or more calls toread_next. -
Adds getter and setter
max_depthmethods to allow setting the maximum JSON parse tree depth if desired, by default it is arbitrarily large (limited by heap memory.) -
Modifies
jsonstatic methodsparse_string,parse_file, andparsebehaviour to throw if there are unconsumed non-whitespace characters after reading one JSON text.
Changes to extensions:
- Changes the top level namespace for the extensions from
jsoncons_exttojsoncons, e.g.jsoncons_ext::csv::csv_readerbecomesjsoncons::csv::csv_reader - Modifies csv_reader and csv_serializer so that the constructors are passed parameters in a
csv_parametersobject rather than ajsonobject. - Adds more options to csv_reader
-
Incorporates test suite files from http://www.json.org/JSON_checker/ into test suite
-
The
jsonconsparser accepts all of the JSON_checker files that its supposed to accept. -
Failures to reject incorrect exponential notation (e.g. [0e+-1]) have been fixed.
-
The
jsonconsparser now rejects all of the JSON_checker files that its supposed to reject except ones with stuff after the end of the document, e.g.["Extra close"]]
(Currently the
jsonconsparser stops after reading a complete JSON text, and supports reading a sequence of JSON texts.) -
Incorporates a fix to operator== on json objects, contributed by Alex Merry
- "Transforming JSON with filters" example fixed
- Added a class-specific in-place new to the json class that is implemented in terms of the global version (required to create json objects with placement new operator.)
- Reorganized header files, removing unnecessary includes.
- Incorporates validation contributed by Alex Merry for ensuring that there is an object or array on parse head.
- Incorporates fix contributed by Milan Burda for “Switch case is in protected scope” clang build error
- Reversion of 0.96 change:
The virtual methods do_float_value, do_integer_value, and do_unsigned_value of json_input_handler and json_outputhandler have been restored to do_double_value, do_longlong_value and do_ulonglong_value, and their typedefed parameter types float_type, integer_type, and unsigned_type have been restored to double, long long, and unsigned long long.
The rationale for this reversion is that the change doesn't really help to make the software more flexible, and that it's better to leave out the typedefs. There will be future enhancements to support greater numeric precision, but these will not affect the current method signatures.
- Fix for "unused variable" warning message
This release includes breaking changes to interfaces. Going forward, the interfaces are expected to be stable.
Breaking changes:
-
Renamed
error_handlertoparse_error_handler. -
Renamed namespace
json_parser_errortojson_parser_errc -
Renamed
value_adaptertojson_type_traits, if you have implemented your own type specializations, you will have to renamevalue_adapteralso. -
Only json arrays now support
operator[](size_t)to loop over values, this is no longer supported forjsonobjects. Use a json object iterator instead. -
The virtual methods
do_double_value,do_integer_valueanddo_uinteger_valueofjson_input_handlerandjson_outputhandlerhave been renamed todo_float_value,do_integer_value, anddo_unsigned_value, and their parameters have been changed fromdouble,long long, andunsigned long longto typedefsfloat_type,integer_type, andunsigned_type. The rationale for this change is to allow different configurations for internal number types (reversed in 0.97.)
General changes
-
jsonmember functionbegin_objectnow returns a bidirectional iterator rather than a random access iterator. -
Static singleton
instancemethods have been added todefault_parse_error_handlerandempty_json_input_handler. -
Added to the
jsonclass overloaded static methods parse, parse_string and parse_file that take aparse_error_handleras a parameter. -
Added methods
last_char()andeof()toparsing_context. -
Enhancements to json parsing and json parse event error notification.
-
Added to
json_input_handlerandjson_output_handlera non virtual methodvaluethat takes a null terminated string. -
Added methods
is_integer,is_unsignedandis_floattojsonto replaceis_longlong,is_ulonglongandis_double, which have been deprecated. -
Added methods
as_integer,as_unsignedandas_floattojsonto replaceis_longlong,is_ulonglongandis_double, which have been deprecated.
Bug fixes:
-
Fixed issue with column number reported by json_reader
-
Where &s[0] and s.length() were passed to methods, &s[0] has been replaced with s.c_str(). While this shouldn't be an issue on most implementations, VS throws an exception in debug modes when the string has length zero.
-
Fixes two issues in 0.95 reported by Alex Merry that caused errors with GCC: a superfluous typename has been removed in csv_serializer.hpp, and a JSONCONS_NOEXCEPT specifier has been added to the json_error_category_impl name method.
-
Fixed a number of typename issues in the 0.96 candidate identifed by Ignatov Serguei.
-
Fixes issues with testsuite cmake and scons reported by Alex Merry and Ignatov Serguei
Enhancements:
-
Added template method
any_casttojsonclass. -
The allocator type parameter in basic_json is now supported, it allows you to supply a custom allocator for dynamically allocated, fixed size small objects in the json container. The allocator type is not used for structures including vectors and strings that use large or variable amounts of memory, these always use the default allocators.
Non-breaking Change:
json_filtermethodparenthas been renamed toinput_handler(old name still works)
Breaking change (if you've implemented your own input and output handlers, or if you've passed json events to input and output handlers directly):
-
The input handler virtual method
name(const std::string& name, const parsing_context& context)has been changed todo_name(const char* p, size_t length, const parsing_context& context) -
The output handler virtual method
name(const std::string& name)has been changed todo_name(const char* p, size_t length) -
The input handler virtual method
string_value(const std::string& value, const parsing_context& context)has been changed todo_string_value(const char* p, size_t length, const parsing_context& context) -
The output handler virtual method
string_value(const std::string& value)has been changed todo_string_value(const char* p, size_t length)
The rationale for the method parameter changes is to allow different internal representations of strings but preserve efficiency.
-
The input and output handler virtual implementation methods begin_json, end_json, begin_object, end_object, begin_array, end_array, name, string_value, longlong_value, ulonglong_value, double_value, bool_value and null_value have been renamed to do_begin_json, do_end_json, do_begin_object, do_end_object, do_begin_array, do_end_array, do_name, do_string_value, do_longlong_value, do_ulonglong_value, do_double_value, do_bool_value and do_null_value and have been made private.
-
Public non-virtual interface methods begin_json, end_json, begin_object, end_object, begin_array, end_array, name have been added to json_input_handler and json_output_handler.
The rationale for these changes is to follow best C++ practices by making the json_input_handler and json_output_handler interfaces public non-virtual and the implementations private virtual. Refer to the documentation and tutorials for details.
- The error_handler virtual implementation methods have been renamed to
do_warninganddo_error, and made private. Non virtual public interface methodswarninganderrorhave been added. Error handling now leveragesstd::error_codeto communicate parser error events in an extendable way.
Bug fixes:
- Fixed bug in csv_reader
Bug fixes:
- Incorporates fix from Alex Merry for comparison of json objects
Bug fixes
- Incorporates contributions from Cory Fields for silencing some compiler warnings
- Fixes bug reported by Vitaliy Gusev in json object operator[size_t]
- Fixes bug in json is_empty method for empty objects
Changes
- json constructors that take string, double etc. are now declared explicit (assignments and defaults to get and make_array methods have their own implementation and do not depend on implicit constructors.)
- make_multi_array renamed to make_array (old name is still supported)
- Previous versions supported any type values through special methods set_custom_data, add_custom_data, and custom_data. This version introduces a new type json::any that wraps any values and works with the usual accessors set, add and as, so the specialized methods are no longer required.
Enhancements
- json get method with default value now accepts extended types as defaults
- json make_array method with default value now accepts extended types as defaults
New extensions
- Added jsoncons_ext/boost/type_extensions.hpp to collect extensions traits for boost types, in particular, for boost::gregorian dates.
New features
- Supports wide character strings and streams with wjson, wjson_reader etc. Assumes UTF16 encoding if sizeof(wchar_t)=2 and UTF32 encoding if sizeof(wchar_t)=4.
- The empty class null_type is added to the jsoncons namespace, it replaces the member type json::null_type (json::null_type is typedefed to jsoncons::null_type for backward compatibility.)
Defect fixes:
- The ascii character 0x7f (del) was not being considered a control character to be escaped, this is fixed.
- Fixed two issues with serialization when the output format property escape_all_non_ascii is enabled. One, the individual bytes were being checked if they were non ascii, rather than first converting to a codepoint. Two, continuations weren't being handled when decoding.
Includes contributed updates for valid compilation and execution in gcc and clang environments
Breaking change (but only if you have subclassed json_input_handler or json_output_handler)
- For consistency with other names, the input and output handler methods new to 0.91 - value_string, value_double, value_longlong, value_ulonglong and value_bool - have been renamed to string_value, double_value, longlong_value, ulonglong_value and bool_value.
Non breaking changes (previous features are deprecated but still work)
-
name_value_pair has been renamed to member_type (typedefed to previous name.)
-
as_string(output_format format) has been deprecated, use the existing to_string(output_format format) instead
Enhancements:
- json now has extensibilty, you can access and modify json values with new types, see the tutorial Extensibility
Preparation for allocator support:
- The basic_json and related classes now have an Storage template parameter, which is currently just a placeholder, but will later provide a hook to allow users to control how json storage is allocated. This addition is transparent to users of the json and related classes.
This release should be largely backwards compatible with 0.90 and 0.83 with two exceptions:
-
If you have used object iterators, you will need to replace uses of std::pair with name_value_pair, in particular, first becomes name() and second becomes value().
-
If you have subclassed json_input_handler, json_output_handler, or json_filter, and have implemented value(const std::string& ..., value(double ..., etc., you will need to modify the names to value_string(const std::string& ..., value_double(double ... (no changes if you are feeding existing implementations.)
The changes are
-
Replaced std::pairstd::string,json with name_value_pair that has accessors name() and value()
-
In json_input_handler and json_output_handler, allowed for overrides of the value methods by making them non-virtual and adding virtual methods value_string, value_double, value_longlong, value_ulonglong, and value_bool
Other new features:
-
Changed implementation of is and as, the current implementation should be user extensible
-
make_multi_array makes a multidimensional array with the number of dimensions specified as a template parameter. Replaces make_2d_array and make_3d_array, which are now deprecated.
-
Added support for is<std::vector> and as<std::vector>
-
Removed JSONCONS_NO_CXX11_RVALUE_REFERENCES, compiler must support move semantics
Incorporates a number of contributions from Pedro Larroy and the developers of the clearskies_core project:
- build system for posix systems
- GCC to list of supported compilers
- Android fix
- fixed virtual destructors missing in json_input_handler, json_output_handler and parsing_context
- fixed const_iterator should be iterator in json_object implementation
To clean up the interface and avoid too much duplicated functionality, we've deprecated some json methods (but they still work)
make_array
Use json val(json::an_array) or json::make_multi_array<1>(...) instead (but make_array will continue to work)
make_2d_array
make_3d_array
Use make_multi_array<2> and make_multi_array<3> instead
as_vector
Use as<std::vector> etc. instead
as_int
as_uint
as_char
Use as, as, and as instead
Fixed issue affecting clang compile
This release should be fully backwards compatible with 0.83.
Includes performance enhancements to json_reader and json_deserializer
Fixes issues with column numbers reported with exceptions
Incorporates a number of patches contributed by Marc Chevrier:
- Fixed issue with set member on json object when a member with that name already exists
- clang port
- cmake build files for examples and test suite
- json template method is for examining the types of json values
- json template method as for accessing json values
Optimizations (very unlikely to break earlier code)
-
get(const std::name& name) const now returns const json& if keyed value exists, otherwise a const reference to json::null
-
get(const std::string& name, const json& default_val) const now returns const json (actually a const proxy that evaluates to json if read)
Bug fixes
- Line number not incremented within multiline comment - fixed
Deprecated features removed
- Removed deprecated output_format properties (too much bagage to carry around)
-
The const version of the json operator[](const std::string& name) didn't need to return a proxy, the return value has been changed to const json& (this change is transparent to the user.)
-
get(const std::name& name) has been changed to return a copy (rather than a reference), and json::null if there is no member with that name (rather than throw.) This way both get methods return default values if no keyed value exists.
-
non-const and const methods json& at(const std::name& name) have been added to replace the old single argument get method. These have the same behavior as the corresponding operator[] functions, but the non-const at is more efficient.
-
Added accessor and modifier methods floatfield to output_format to provide a supported way to set the floatfield format flag to fixed or scientific with a specified number of decimal places (this can be done in older versions, but only with deprecated methods.)
-
The default constructor now constructs an empty object (rather than a null object.) While this is a change, it's unlikely to break exisitng code (all test cases passed without modification.)
This means that instead of
json obj(json::an_object);
obj["field"] = "field";
you can simply write
json obj;
obj["field"] = "field";
The former notation is still supported, though.
-
Added a version of 'resize_array' to json that resizes the array to n elements and initializes them to a specified value.
-
Added a version of the static method json::make_array that takes no arguments and makes an empty json array
Note that
json arr(json::an_array);
is equivalent to
json arr = json::make_array();
and
json arr(json::an_array);
arr.resize_array(10,0.0);
is equivalent to
json arr = json::make_array(10,0.0);
For consistency the json::make_array notation is now favored in the documentation.
-
Added resize_array method to json for resizing json arrays
-
Fixed issue with remove_range method (templated code failed to compile if calling this method.)
-
Added remove_member method to remove a member from a json object
-
Fixed issue with multiline line comments, added test case
-
Fixed issue with adding custom data to a json array using add_custom_data, added examples.
-
Since 0.50, jsoncons has used snprintf for default serialization of double values to string values. This can result in invalid json output when running on a locale like German or Spanish. The period character (‘.’) is now always used as the decimal point, non English locales are ignored.
-
The output_format methods that support alternative floating point formatting, e.g. fixed, have been deprecated.
-
Added a template method as_vector to the json class. If a json value is an array and conversion is possible to the template type, returns a std::vector of that type, otherwise throws an std::exception. Specializations are provided for std::string, bool, char, int, unsigned int, long, unsigned long, long long, unsigned long long, and double. For example
std::string s("[0,1,2,3]");
json val = json::parse_string(s);
std::vector v = val.as_vector();
-
Undeprecated the json member function precision
This release (0.60b) is fully backwards compatible with 0.50.
A change introduced with 0.60 has been reversed. 0.60 introduced an alternative method of constructing a json arrray or object with an initial default constructor, a bug with this was fixed in 0.60a, but this feature and related documentation has been removed because it added complexity but no real value.
-
Added swap member function to json
-
Added add and add_custom_data overrides to json that take an index value, for adding a new element at the specified index and shifting all elements currently at or above that index to the right.
-
Added capacity member functions to json
- csv_serializer has been added to the csv extension
This release is fully backwards compatible with 0.4*, and mostly backwards compatible to 0.32 apart from the two name changes in 0.41
Bug fixes
- When reading the escaped characters "\b", "\f", "\r" and "\t" appearing in json strings, json_reader was replacing them with the linefeed character, this has been fixed.
Deprecated
- Deprecated modifiers precision and fixed_decimal_places from output_format. Use set_floating_point_format instead.
- Deprecated constructor that takes indenting parameter from output_format. For pretty printing with indenting, use the pretty_print function or pass the indenting parameter in json_serializer.
Changes
- When serializing floating point values to a stream, previous versions defaulted to default floating point precision with a precision of 16. This has been changed to truncate trailing zeros but keep one if immediately after a decimal point.
New features
- For line reporting in parser error messages, json_reader now recognizes \r\n, \n alone or \r alone (\r alone is new.)
- Added set_floating_point_format methods to output_format to give more control over floating point notation.
Non functional enhancements
- json_reader now estimates the minimum capacity for arrays and objects, and reports that information for the begin_array and begin_object events. This greatly reduces reallocations.
- Fixed another bug with multi line /**/ comments
- Minor fixes to reporting line and column number of errors
- Added fixed_decimal_places setter to output_format
- Added version of as_string to json that takes output_format as a parameter
- Reorganization of test cases and examples in source tree
- Added non-member overload swap(json& a, json& b)
- Fixed bug with multi line /**/ comments
- Added begin_json and end_json methods to json_output_handler
- json_deserializer should now satisfy basic exception safety (no leak guarantee)
- Moved csv_reader.hpp to jsoncons_ext/csv directory
- Changed csv_reader namespace to jsoncons::csv
- json::parse_file no longer reads the entire file into memory before parsing (it now uses json_reader default buffering)
-
json_listener renamed to json_input_handler
-
json_writer renamed to json_output_handler
-
Added json_filter class
-
json get method that takes default argument now returns a value rather than a reference
-
Issue in csv_reader related to get method issue fixed
-
Issue with const json operator[] fixed
-
Added as_char method to json
-
Improved exception safety, some opportunites for memory leaks in the presence of exceptions removed
Added reserve method to json
Added static make_3d_array method to json
json_reader now configured for buffered reading
Added csv_reader class for reading CSV files and producing JSON events
Fixed bug with explicitly passing output_format in pretty_print.
Added remove_range method, operator== and operator!= to proxy and json objects
Added static methods make_array and make_2d_array to json
error_handler method content_error renamed to error
Added error_code to warning, error and fatal_error methods of error_handler
json_in_stream renamed to json_listener
json_out_stream renamed to json_writer
Added buffer accessor method to parsing_context
Added parsing_context class for providing information about the element being parsed.
error_handler methods take message and parsing_context parameters
json_in_stream handlers take parsing_context parameter
Added error_handler class for json_reader
Made json_exception a base class for all json exceptions
Added root() method to json_deserializer to get a reference to the json value
Removed swap_root() method from json_deserializer
Renamed serialize() class method to to_stream() in json
Custom data serialization supported through template function specialization of serialize (reverses change in 0.17)
Added is_custom() method to json and proxy
get_custom() method renamed to custom_data() in json and proxy
Added clear() method to json and proxy
set_member() method renamed to set()
set_custom() method renamed to set_custom_data()
push_back() method renamed to add() in json and proxy
Added add_custom_data method() in json and proxy
Custom data serialization supported through template class specialization of custom_serialization (replaces template function specialization of serialize)
Change to json_out_stream and json_serializer:
void value(const custom_data& value)
removed.
Free function serialize replaces free function to_stream for serializing custom data.
pretty print tidied up for nested arrays
Made eof() method on json_reader public, to support reading multiple JSON objects from a stream.
Added pretty_print class
Renamed json_stream_writer to json_serializer, implements pure virtual class json_out_stream
Renamed json_stream_listener to json_deserializer implements pure virtual class json_in_stream
Renamed json_parser to json_reader, parse to read.
Changed indenting so object and array members start on new line.
Added support for storing user data in json object, and serializing to JSON.
Replaced simple_string union member with json_string that wraps std::basic_string
name() and value() event handler methods on basic_json_stream_writer take const std::basic_string& rather than const Char* and length.
Implemented operator<< for json::proxy
Added to_stream methods to json::proxy
Added members to json_parser to access and modify the buffer capacity
Added checks when parsing integer values to determine overflow for long long and unsigned long long, and if overflow, parse them as doubles.