Coder Social home page Coder Social logo

danielaparker / jsoncons Goto Github PK

View Code? Open in Web Editor NEW
682.0 37.0 160.0 47.59 MB

A C++, header-only library for constructing JSON and JSON-like data formats, with JSON Pointer, JSON Patch, JSON Schema, JSONPath, JMESPath, CSV, MessagePack, CBOR, BSON, UBJSON

Home Page: https://danielaparker.github.io/jsoncons

License: Other

C++ 99.63% CMake 0.31% Shell 0.06%
json cbor jsonpath csv json-pointer json-patch messagepack json-diff cpp json-serialization

jsoncons's Introduction

JSONCONS

jsoncons is a C++, header-only library for constructing JSON and JSON-like data formats such as CBOR. For each supported data format, it enables you to work with the data in a number of ways:

  • As a variant-like data structure, basic_json

  • As a strongly typed C++ data structure that implements json_type_traits

  • With cursor-level access to a stream of parse events, somewhat analogous to StAX pull parsing and push serializing in the XML world.

Compared to other JSON libraries, jsoncons has been designed to handle very large JSON texts. At its heart are SAX-style parsers and serializers. It supports reading an entire JSON text in memory in a variant-like structure. But it also supports efficient access to the underlying data using StAX-style pull parsing and push serializing. And it supports incremental parsing into a user's preferred form, using information about user types provided by specializations of json_type_traits.

The jsoncons data model supports the familiar JSON types - nulls, booleans, numbers, strings, arrays, objects - plus byte strings. In addition, jsoncons supports semantic tagging of datetimes, epoch times, big integers, big decimals, big floats and binary encodings. This allows it to preserve these type semantics when parsing JSON-like data formats such as CBOR that have them.

jsoncons is distributed under the Boost Software License.

jsoncons is free but welcomes support to sustain its development. If you find this library helpful, please consider making a one time donation or becoming a ❤️ sponsor.

As the jsoncons library has evolved, names have sometimes changed. To ease transition, jsoncons deprecates the old names but continues to support many of them. The deprecated names can be suppressed by defining the macro JSONCONS_NO_DEPRECATED, and doing so is recommended for new code.

Extensions

What users say

"Apache Kvrocks consistently utilizes jsoncons to offer support for JSON data structures to users. We find the development experience with jsoncons outstanding!"

"I have been using your library in my native language – R – and have created an R package making it easy for (a) JMESpath and JSONpath queries on JSON strings or R objects and (b) for other R developers to link to your library."

"I’m using your library for an external interface to pass data, as well as using the conversions from csv to json, which are really helpful for converting data for use in javascript"

"Verified that, for my needs in JSON and CBOR, it is working perfectly"

"the JSONPath feature of this library, it's great"

"We use JMESPath implementation quite extensively"

"We love your JSON Schema validator. We are using it in ER/Studio our data modelling tool to parse JSON Schema files so we can create entity relations models from them."

"the serialization lib of choice with its beautiful mappings and ease of use"

"really good" "awesome project" "very solid and very dependable" "my team loves it" "Your repo rocks!!!!!"

Get jsoncons

You can use the vcpkg platform library manager to install the jsoncons package.

Or, download the latest release and unpack the zip file. Copy the directory include/jsoncons to your include directory. If you wish to use extensions, copy include/jsoncons_ext as well.

Or, download the latest code on main.

How to use it

The library requires a C++ Compiler with C++11 support. In addition the library defines jsoncons::endian, jsoncons::basic_string_view, jsoncons::optional, and jsoncons::span, which will be typedefed to their standard library equivalents if detected. Otherwise they will be typedefed to internal, C++11 compatible, implementations.

The library uses exceptions and in some cases std::error_code's to report errors. Apart from jsoncons::assertion_error, all jsoncons exception classes implement the jsoncons::json_error interface. If exceptions are disabled or if the compile time macro JSONCONS_NO_EXCEPTIONS is defined, throws become calls to std::terminate.

Benchmarks

json_benchmarks provides some measurements about how jsoncons compares to other json libraries.

JSONPath Comparison shows how jsoncons JsonPath compares with other implementations

Examples

Working with JSON data

Working with CBOR data

Working with JSON data

For the examples below you need to include some header files and initialize a string of JSON data:

#include <jsoncons/json.hpp>
#include <jsoncons_ext/jsonpath/jsonpath.hpp>
#include <iostream>

using namespace jsoncons; // for convenience

std::string data = R"(
    {
       "application": "hiking",
       "reputons": [
       {
           "rater": "HikingAsylum",
           "assertion": "advanced",
           "rated": "Marilyn C",
           "rating": 0.90,
           "generated": 1514862245
         }
       ]
    }
)";

jsoncons allows you to work with the data in a number of ways:

As a variant-like data structure

int main()
{
    // Parse the string of data into a json value
    json j = json::parse(data);

    // Does object member reputons exist?
    std::cout << "(1) " << std::boolalpha << j.contains("reputons") << "\n\n";

    // Get a reference to reputons array 
    const json& v = j["reputons"]; 

    // Iterate over reputons array 
    std::cout << "(2)\n";
    for (const auto& item : v.array_range())
    {
        // Access rated as string and rating as double
        std::cout << item["rated"].as<std::string>() << ", " << item["rating"].as<double>() << "\n";
    }
    std::cout << "\n";

    // Select all "rated" with JSONPath
    std::cout << "(3)\n";
    json result = jsonpath::json_query(j,"$..rated");
    std::cout << pretty_print(result) << "\n\n";

    // Serialize back to JSON
    std::cout << "(4)\n" << pretty_print(j) << "\n\n";
}

Output:

(1) true

(2)
Marilyn C, 0.9

(3)
[
    "Marilyn C"
]

(4)
{
    "application": "hiking",
    "reputons": [
        {
            "assertion": "advanced",
            "generated": 1514862245,
            "rated": "Marilyn C",
            "rater": "HikingAsylum",
            "rating": 0.9
        }
    ]
}

As a strongly typed C++ data structure

jsoncons supports transforming JSON texts into C++ data structures. The functions decode_json and encode_json convert strings or streams of JSON data to C++ data structures and back. Decode and encode work for all C++ classes that have json_type_traits defined. jsoncons already supports many types in the standard library, and your own types will be supported too if you specialize json_type_traits in the jsoncons namespace.

namespace ns {
    enum class hiking_experience {beginner,intermediate,advanced};

    class hiking_reputon
    {
        std::string rater_;
        hiking_experience assertion_;
        std::string rated_;
        double rating_;
        std::optional<std::chrono::seconds> generated_; // assumes C++17, if not use jsoncons::optional
        std::optional<std::chrono::seconds> expires_;
    public:
        hiking_reputon(const std::string& rater,
                       hiking_experience assertion,
                       const std::string& rated,
                       double rating,
                       const std::optional<std::chrono::seconds>& generated = 
                           std::optional<std::chrono::seconds>(),
                       const std::optional<std::chrono::seconds>& expires = 
                           std::optional<std::chrono::seconds>())
            : rater_(rater), assertion_(assertion), rated_(rated), rating_(rating),
              generated_(generated), expires_(expires)
        {
        }

        const std::string& rater() const {return rater_;}
        hiking_experience assertion() const {return assertion_;}
        const std::string& rated() const {return rated_;}
        double rating() const {return rating_;}
        std::optional<std::chrono::seconds> generated() const {return generated_;}
        std::optional<std::chrono::seconds> expires() const {return expires_;}

        friend bool operator==(const hiking_reputon& lhs, const hiking_reputon& rhs)
        {
            return lhs.rater_ == rhs.rater_ && lhs.assertion_ == rhs.assertion_ && 
                   lhs.rated_ == rhs.rated_ && lhs.rating_ == rhs.rating_ &&
                   lhs.confidence_ == rhs.confidence_ && lhs.expires_ == rhs.expires_;
        }

        friend bool operator!=(const hiking_reputon& lhs, const hiking_reputon& rhs)
        {
            return !(lhs == rhs);
        };
    };

    class hiking_reputation
    {
        std::string application_;
        std::vector<hiking_reputon> reputons_;
    public:
        hiking_reputation(const std::string& application, 
                          const std::vector<hiking_reputon>& reputons)
            : application_(application), 
              reputons_(reputons)
        {}

        const std::string& application() const { return application_;}
        const std::vector<hiking_reputon>& reputons() const { return reputons_;}
    };

} // namespace ns

// Declare the traits. Specify which data members need to be serialized.

JSONCONS_ENUM_TRAITS(ns::hiking_experience, beginner, intermediate, advanced)
// First four members listed are mandatory, generated and expires are optional
JSONCONS_N_CTOR_GETTER_TRAITS(ns::hiking_reputon, 4, rater, assertion, rated, rating, 
                              generated, expires)

// All members are mandatory
JSONCONS_ALL_CTOR_GETTER_TRAITS(ns::hiking_reputation, application, reputons)

int main()
{
    // Decode the string of data into a c++ structure
    ns::hiking_reputation v = decode_json<ns::hiking_reputation>(data);

    // Iterate over reputons array value
    std::cout << "(1)\n";
    for (const auto& item : v.reputons())
    {
        std::cout << item.rated() << ", " << item.rating();
        if (item.generated())
        {
            std::cout << ", " << (*item.generated()).count();
        }
        std::cout << "\n";
    }

    // Encode the c++ structure into a string
    std::string s;
    encode_json(v, s, indenting::indent);
    std::cout << "(2)\n";
    std::cout << s << "\n";
}

Output:

(1)
Marilyn C, 0.9, 1514862245
(2)
{
    "application": "hiking",
    "reputons": [
        {
            "assertion": "advanced",
            "generated": 1514862245,
            "rated": "Marilyn C",
            "rater": "HikingAsylum",
            "rating": 0.9
        }
    ]
}

This example makes use of the convenience macros JSONCONS_ENUM_TRAITS, JSONCONS_N_CTOR_GETTER_TRAITS, and JSONCONS_ALL_CTOR_GETTER_TRAITS to specialize the json_type_traits for the enum type ns::hiking_experience, the class ns::hiking_reputon (with some non-mandatory members), and the class ns::hiking_reputation (with all mandatory members.) The macro JSONCONS_ENUM_TRAITS generates the code from the enum identifiers, and the macros JSONCONS_N_CTOR_GETTER_TRAITS and JSONCONS_ALL_CTOR_GETTER_TRAITS generate the code from the get functions and a constructor. These macro declarations must be placed outside any namespace blocks.

See examples for other ways of specializing json_type_traits.

With cursor-level access

A typical pull parsing application will repeatedly process the current() event and call next() to advance to the next event, until done() returns true.

int main()
{
    json_string_cursor cursor(data);
    for (; !cursor.done(); cursor.next())
    {
        const auto& event = cursor.current();
        switch (event.event_type())
        {
            case staj_event_type::begin_array:
                std::cout << event.event_type() << " " << "\n";
                break;
            case staj_event_type::end_array:
                std::cout << event.event_type() << " " << "\n";
                break;
            case staj_event_type::begin_object:
                std::cout << event.event_type() << " " << "\n";
                break;
            case staj_event_type::end_object:
                std::cout << event.event_type() << " " << "\n";
                break;
            case staj_event_type::key:
                // Or std::string_view, if supported
                std::cout << event.event_type() << ": " << event.get<jsoncons::string_view>() << "\n";
                break;
            case staj_event_type::string_value:
                // Or std::string_view, if supported
                std::cout << event.event_type() << ": " << event.get<jsoncons::string_view>() << "\n";
                break;
            case staj_event_type::null_value:
                std::cout << event.event_type() << "\n";
                break;
            case staj_event_type::bool_value:
                std::cout << event.event_type() << ": " << std::boolalpha << event.get<bool>() << "\n";
                break;
            case staj_event_type::int64_value:
                std::cout << event.event_type() << ": " << event.get<int64_t>() << "\n";
                break;
            case staj_event_type::uint64_value:
                std::cout << event.event_type() << ": " << event.get<uint64_t>() << "\n";
                break;
            case staj_event_type::double_value:
                std::cout << event.event_type() << ": " << event.get<double>() << "\n";
                break;
            default:
                std::cout << "Unhandled event type: " << event.event_type() << " " << "\n";
                break;
        }
    }    
}

Output:

begin_object
key: application
string_value: hiking
key: reputons
begin_array
begin_object
key: rater
string_value: HikingAsylum
key: assertion
string_value: advanced
key: rated
string_value: Marilyn C
key: rating
double_value: 0.9
key: generated
uint64_value: 1514862245
end_object
end_array
end_object

You can apply a filter to a cursor using the pipe syntax (e.g., cursor | filter1 | filter2 | ...)

int main()
{
    std::string name;
    auto filter = [&](const staj_event& ev, const ser_context&) -> bool
    {
        if (ev.event_type() == staj_event_type::key)
        {
            name = ev.get<std::string>();
            return false;
        }
        if (name == "rated")
        {
            name.clear();
            return true;
        }
        return false;
    };

    json_string_cursor cursor(data);
    auto filtered_c = cursor | filter;

    for (; !filtered_c.done(); filtered_c.next())
    {
        const auto& event = filtered_c.current();
        switch (event.event_type())
        {
            case staj_event_type::string_value:
                // Or std::string_view, if C++17
                std::cout << event.event_type() << ": " << event.get<jsoncons::string_view>() << "\n";
                break;
            default:
                std::cout << "Unhandled event type\n";
                break;
        }
    }
}    

Output:

Marilyn C

Working with CBOR data

For the examples below you need to include some header files and initialize a buffer of CBOR data:

#include <iomanip>
#include <iostream>
#include <jsoncons/json.hpp>
#include <jsoncons_ext/cbor/cbor.hpp>
#include <jsoncons_ext/jsonpath/jsonpath.hpp>

using namespace jsoncons; // for convenience

const std::vector<uint8_t> data = {
    0x9f, // Start indefinte length array
      0x83, // Array of length 3
        0x63, // String value of length 3
          0x66,0x6f,0x6f, // "foo" 
        0x44, // Byte string value of length 4
          0x50,0x75,0x73,0x73, // 'P''u''s''s'
        0xc5, // Tag 5 (bigfloat)
          0x82, // Array of length 2
            0x20, // -1
            0x03, // 3   
      0x83, // Another array of length 3
        0x63, // String value of length 3
          0x62,0x61,0x72, // "bar"
        0xd6, // Expected conversion to base64
        0x44, // Byte string value of length 4
          0x50,0x75,0x73,0x73, // 'P''u''s''s'
        0xc4, // Tag 4 (decimal fraction)
          0x82, // Array of length 2
            0x38, // Negative integer of length 1
              0x1c, // -29
            0xc2, // Tag 2 (positive bignum)
              0x4d, // Byte string value of length 13
                0x01,0x8e,0xe9,0x0f,0xf6,0xc3,0x73,0xe0,0xee,0x4e,0x3f,0x0a,0xd2,
    0xff // "break"
};

jsoncons allows you to work with the CBOR data similarly to JSON data:

As a variant-like data structure

int main()
{
    // Parse the CBOR data into a json value
    json j = cbor::decode_cbor<json>(data);

    // Pretty print
    std::cout << "(1)\n" << pretty_print(j) << "\n\n";

    // Iterate over rows
    std::cout << "(2)\n";
    for (const auto& row : j.array_range())
    {
        std::cout << row[1].as<jsoncons::byte_string>() << " (" << row[1].tag() << ")\n";
    }
    std::cout << "\n";

    // Select the third column with JSONPath
    std::cout << "(3)\n";
    json result = jsonpath::json_query(j,"$[*][2]");
    std::cout << pretty_print(result) << "\n\n";

    // Serialize back to CBOR
    std::vector<uint8_t> buffer;
    cbor::encode_cbor(j, buffer);
    std::cout << "(4)\n" << byte_string_view(buffer) << "\n\n";
}

Output:

(1)
[
    ["foo", "UHVzcw", "0x3p-1"],
    ["bar", "UHVzcw==", "1.23456789012345678901234567890"]
]

(2)
50,75,73,73 (n/a)
50,75,73,73 (base64)

(3)
[
    "0x3p-1",
    "1.23456789012345678901234567890"
]

(4)
82,83,63,66,6f,6f,44,50,75,73,73,c5,82,20,03,83,63,62,61,72,d6,44,50,75,73,73,c4,82,38,1c,c2,4d,01,8e,e9,0f,f6,c3,73,e0,ee,4e,3f,0a,d2

As a strongly typed C++ data structure

int main()
{
    // Parse the string of data into a std::vector<std::tuple<std::string,jsoncons::byte_string,std::string>> value
    auto val = cbor::decode_cbor<std::vector<std::tuple<std::string,jsoncons::byte_string,std::string>>>(data);

    std::cout << "(1)\n";
    for (const auto& row : val)
    {
        std::cout << std::get<0>(row) << ", " << std::get<1>(row) << ", " << std::get<2>(row) << "\n";
    }
    std::cout << "\n";

    // Serialize back to CBOR
    std::vector<uint8_t> buffer;
    cbor::encode_cbor(val, buffer);
    std::cout << "(2)\n" << byte_string_view(buffer) << "\n\n";
}

Output:

(1)
foo, 50,75,73,73, 0x3p-1
bar, 50,75,73,73, 1.23456789012345678901234567890

(2)
82,9f,63,66,6f,6f,44,50,75,73,73,66,30,78,33,70,2d,31,ff,9f,63,62,61,72,44,50,75,73,73,78,1f,31,2e,32,33,34,35,36,37,38,39,30,31,32,33,34,35,36,37,38,39,30,31,32,33,34,35,36,37,38,39,30,ff

Note that when decoding the bigfloat and decimal fraction into a std::string, we lose the semantic information that the variant like data structure preserved with a tag, so serializing back to CBOR produces a text string.

With cursor-level access

A typical pull parsing application will repeatedly process the current() event and call next() to advance to the next event, until done() returns true.

int main()
{
    cbor::cbor_bytes_cursor cursor(data);
    for (; !cursor.done(); cursor.next())
    {
        const auto& event = cursor.current();
        switch (event.event_type())
        {
            case staj_event_type::begin_array:
                std::cout << event.event_type() << " " << "(" << event.tag() << ")\n";
                break;
            case staj_event_type::end_array:
                std::cout << event.event_type() << " " << "(" << event.tag() << ")\n";
                break;
            case staj_event_type::begin_object:
                std::cout << event.event_type() << " " << "(" << event.tag() << ")\n";
                break;
            case staj_event_type::end_object:
                std::cout << event.event_type() << " " << "(" << event.tag() << ")\n";
                break;
            case staj_event_type::key:
                // Or std::string_view, if supported
                std::cout << event.event_type() << ": " << event.get<jsoncons::string_view>() << " " << "(" << event.tag() << ")\n";
                break;
            case staj_event_type::string_value:
                // Or std::string_view, if supported
                std::cout << event.event_type() << ": " << event.get<jsoncons::string_view>() << " " << "(" << event.tag() << ")\n";
                break;
            case staj_event_type::byte_string_value:
                std::cout << event.event_type() << ": " << event.get<jsoncons::span<const uint8_t>>() << " " << "(" << event.tag() << ")\n";
                break;
            case staj_event_type::null_value:
                std::cout << event.event_type() << " " << "(" << event.tag() << ")\n";
                break;
            case staj_event_type::bool_value:
                std::cout << event.event_type() << ": " << std::boolalpha << event.get<bool>() << " " << "(" << event.tag() << ")\n";
                break;
            case staj_event_type::int64_value:
                std::cout << event.event_type() << ": " << event.get<int64_t>() << " " << "(" << event.tag() << ")\n";
                break;
            case staj_event_type::uint64_value:
                std::cout << event.event_type() << ": " << event.get<uint64_t>() << " " << "(" << event.tag() << ")\n";
                break;
            case staj_event_type::half_value:
            case staj_event_type::double_value:
                std::cout << event.event_type() << ": "  << event.get<double>() << " " << "(" << event.tag() << ")\n";
                break;
            default:
                std::cout << "Unhandled event type " << event.event_type() << " " << "(" << event.tag() << ")\n";
                break;
        }
    }
}

Output:

begin_array (n/a)
begin_array (n/a)
string_value: foo (n/a)
byte_string_value: 50,75,73,73 (n/a)
string_value: 0x3p-1 (bigfloat)
end_array (n/a)
begin_array (n/a)
string_value: bar (n/a)
byte_string_value: 50,75,73,73 (base64)
string_value: 1.23456789012345678901234567890 (bigdec)
end_array (n/a)
end_array (n/a)

You can apply a filter to a cursor using the pipe syntax,

int main()
{
    auto filter = [&](const staj_event& ev, const ser_context&) -> bool
    {
        return (ev.tag() == semantic_tag::bigdec) || (ev.tag() == semantic_tag::bigfloat);  
    };

    cbor::cbor_bytes_cursor cursor(data);
    auto filtered_c = cursor | filter;

    for (; !filtered_c.done(); filtered_c.next())
    {
        const auto& event = filtered_c.current();
        switch (event.event_type())
        {
            case staj_event_type::string_value:
                // Or std::string_view, if supported
                std::cout << event.event_type() << ": " << event.get<jsoncons::string_view>() << " " << "(" << event.tag() << ")\n";
                break;
            default:
                std::cout << "Unhandled event type " << event.event_type() << " " << "(" << event.tag() << ")\n";
                break;
        }
    }
}

Output:

string_value: 0x3p-1 (bigfloat)
string_value: 1.23456789012345678901234567890 (bigdec)

Supported compilers

jsoncons requires a compiler with minimally C++11 support. It is tested in continuous integration on Github Actions and circleci. UndefinedBehaviorSanitizer (UBSan) diagnostics are enabled for selected gcc and clang builds. Since v0.151.0, it is integrated with Google OSS-fuzz, with coverage for all parsers and encoders.

Compiler Version Standard Architecture Operating System CI Service
Visual Studio vs2019 default x86, x64 Windows 11 GitHub Actions
vs2022 default x86, x64 Windows 11 GitHub Actions
Visual Studio - clang vs2019 default x86, x64 Windows 11 GitHub Actions
vs2022 default x86, x64 Windows 11 GitHub Actions
g++ 6, 7, 8, 9, 10, 11, 12 default x64 Ubuntu circleci
g++ 12 c++20 x64 Ubuntu GitHub Actions
clang 3.9, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 default x64 Ubuntu circleci
clang 14 c++20 x64 Ubuntu GitHub Actions
clang xcode 11, 12, 13 default x64 OSX 11 GitHub Actions
clang xcode 13, 14 default x64 OSX 12 GitHub Actions

Building the test suite and examples with CMake

CMake is a cross-platform build tool that generates makefiles and solutions for the compiler environment of your choice. On Windows you can download a Windows Installer package. On Linux it is usually available as a package, e.g., on Ubuntu,

sudo apt-get install cmake

Once cmake is installed, you can build and run the unit tests from the jsoncons directory,

On Windows:

> mkdir build
> cd build
> cmake .. -DJSONCONS_BUILD_TESTS=On
> cmake --build .
> ctest -C Debug --output-on-failure

On UNIX:

$ mkdir build
$ cd build
$ cmake .. -DJSONCONS_BUILD_TESTS=On
$ cmake --build .
$ ctest --output-on-failure

Acknowledgements

jsoncons uses the PVS-Studio static analyzer, provided free for open source projects.

A big thanks to the comp.lang.c++ community for help with implementation details.

The jsoncons platform dependent binary configuration draws on to the excellent MIT licensed tinycbor.

Thanks to Milo Yip, author of RapidJSON, for raising the quality of JSON libraries across the board, by publishing the benchmarks, and contacting this project (among others) to share the results.

The jsoncons implementation of the Grisu3 algorithm for printing floating-point numbers follows Florian Loitsch's MIT licensed grisu3_59_56 implementation, with minor modifications.

The macro JSONCONS_ALL_MEMBER_TRAITS follows the approach taken by Martin York's ThorsSerializer

The jsoncons implementations of BSON decimal128 to and from string, and ObjectId to and from string, are based on the Apache 2 licensed libbson.

Special thanks to our contributors

jsoncons's People

Contributors

amassalha avatar amerry avatar bow-fujita avatar cschreib-ibex avatar danielaparker avatar davidkorczynski avatar dependabot[bot] avatar dpsi avatar ecorm avatar gerdy-d avatar hongweipeng avatar jpritikin avatar konstantinplotnikov avatar larroy avatar markapola avatar mikewallis avatar monkeybreadsoftware avatar mtmorgan avatar naveensrinivasan avatar neandreithal avatar oleh-derevenko avatar patternoia avatar phdittmann avatar prince-chrismc avatar raplonu avatar romange avatar rupertsteel avatar theuni avatar wbangna avatar xezon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jsoncons's Issues

.get("key",stringval).as<std::string>(); fails

on master this crashes for me on VS2013

#include "jsoncons/json.hpp"
#include <string>
#include <iostream>

using namespace jsoncons;
using std::string;

int main(int argc, char **argv)
{
  json example;
  string result = example.get("test", string("too long string for short string")).as<string>();
  std::cout << "result:" << result << std::endl;
  return 0;
}

Throws a bad_alloc on both master and the last tag during retrieving in as<string>()

Having problem with using `json::an_object`

I am trying to create a json object with a key-value like below

json config;
json xfile_opt(json::an_object);
xfile_opt.add("input-file", config_file);
config["XFILE_COMPATIBLE"] = std::move(xfile_opt);

but it seems i cannot make it right.
And also i couldn't find any documentation addressing my problem.

How can i accomplish this?
Thanks in advance

remove_member removes incorrect members

Hi,

The function remove_members doesn't work as expected due to a bug in json_object_impl::remove. It's using lower_bound but doesn't verify that the element was in the vector.
The original code is:

void remove(const std::basic_string<Char>& name) 
{
    key_compare<Char,Alloc> comp;
    auto it = std::lower_bound(members_.begin(),members_.end(), name, comp);
    if (it != members_.end())
    {
        members_.erase(it);
    }
}

it should be:

void remove(const std::basic_string<Char>& name) 
{
    key_compare<Char,Alloc> comp;
    auto it = std::lower_bound(members_.begin(),members_.end(), name, comp);
    if (it != members_.end() && it->first == name)
    {
        members_.erase(it);
    }
}

Also few lines above, if used, the const version of find wouldn't compile:

const_iterator find(const std::basic_string<Char>& name) const
{
    key_compare<Char,Alloc> comp;
    auto it = std::lower_bound(members_.begin(),members_.end(), name, comp);
    return (it != members_.end() && it->name() == name) ? const_iterator(it) : end();
}

it should be:

const_iterator find(const std::basic_string<Char>& name) const
{
    key_compare<Char,Alloc> comp;
    auto it = std::lower_bound(members_.begin(),members_.end(), name, comp);
    return (it != members_.end() && it->first == name) ? const_iterator(it) : end();
}

Thanks

How to use the union operator in the query

Hi Daniel,

Thanks for the library. I am trying to use the lib in filtering the JSON to get only certain values. Consider a JSON string like this:

{
  "firstName": "John",
  "lastName" : "doe",
  "age"      : 26,
  "address"  : {
    "streetAddress": "naist street",
    "city"         : "Nara",
    "postalCode"   : "630-0192"
  },
  "phoneNumbers": [
    {
      "type"  : "iPhone",
      "number": "0123-4567-8888"
    },
    {
      "type"  : "home",
      "number": "0123-4567-8910"
    }
  ]
}

I just want firstname and lastname in the result

I tried the expression
json result = json_query(testjson, "$[firstName,lastName]");

I get an empty array.

On debugging the code I saw that when the expression is evaluated the find_elements() function only checks array types for the '[' brackets. I just want to know if I have my expression wrong. I did verify the expression at http://jsonpath.com/ and it worked fine.

Thanks,
Amit

Compilation Error: No member named 'assign'

I'm getting the following compilation error:
json.hpp:1698:41: No member named 'assign' in 'jsoncons::json_type_traits<jsoncons::basic_json<char, jsoncons::json_traits, std::__1::allocator >, std::__1::__bit_const_reference<std::__1::vector<bool, std::__1::allocator > > >'

template <class T>
    basic_json(T val)
        : var_(null_type())
    {
        json_type_traits<value_type,T>::assign(*this,val);
    }

Lack of accessor methods

Hello.

I have a question about accessor methods for members and elements.
Now I should write something like this to get value of specific member by index:

if (NodeRec.is_object())
{
  auto Members = NodeRec.members();
  const auto& vv = Members.begin().get()[Col].value();
  // do something with vv
}

It would be nice to get ability write something like this:

auto Members = NodeRec.members();
const auto& vv = Members[Col].value();  // or Members.value(Col);

error: need ‘typename’ before ...

Hi.
First of all, sorry for my bad english.
Second, I'm trying to compile your test suite but I get some errors.
The first seems due to the fact that my compiler (g++ 4.9.2 on a Debian Jessie amd64) requires the keyword "typename" before (jsoncons/json_structures.hpp:829)

std::vector<value_type,allocator_type>::iterator it;

Changin in

typename std::vector<value_type,allocator_type>::iterator it

the compilation continue.

I transcribe, below, the output

--- begin output ---
[ 3%] Building CXX object CMakeFiles/jsoncons_tests.dir/home/max/big/src/jsoncons-git/jsoncons/test_suite/src/json_construction_tests.cpp.o
In file included from /home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons/json.hpp:19:0,
from /home/max/big/src/jsoncons-git/jsoncons/test_suite/src/json_construction_tests.cpp:10:
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons/json_structures.hpp: In member function ‘jsoncons::json_object<StringT, JsonT, Alloc>::iterator jsoncons::json_object<StringT, JsonT, Alloc>::set(jsoncons::json_object<StringT, JsonT, Alloc>::iterator, jsoncons::json_object<StringT, JsonT, Alloc>::string_type&&, JsonT&&)’:
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons/json_structures.hpp:829:9: error: need ‘typename’ before ‘std::vector<jsoncons::name_value_pair<StringT, JsonT>, Alloc>::iterator’ because ‘std::vector<jsoncons::name_value_pair<StringT, JsonT>, Alloc>’ is a dependent scope
std::vector<value_type,allocator_type>::iterator it;
^
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons/json_structures.hpp:829:58: error: expected ‘;’ before ‘it’
std::vector<value_type,allocator_type>::iterator it;
^
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons/json_structures.hpp:832:13: error: ‘it’ was not declared in this scope
it = std::lower_bound(hint.get(),members_.end(),name.data() ,member_lt_string<value_type,char_type>(name.length()));
^
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons/json_structures.hpp:836:13: error: ‘it’ was not declared in this scope
it = std::lower_bound(members_.begin(),members_.end(),name.data() ,member_lt_string<value_type,char_type>(name.length()));
^
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons/json_structures.hpp:839:13: error: ‘it’ was not declared in this scope
if (it == members_.end())
^
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons/json_structures.hpp:852:25: error: ‘it’ was not declared in this scope
return iterator(it);
^
In file included from /home/max/big/src/jsoncons-git/jsoncons/test_suite/src/json_construction_tests.cpp:10:0:
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons/json.hpp: At global scope:
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons/json.hpp:2736:25: error: declaration of ‘typedef jsoncons::basic_json<StringT, Alloc>::member_type jsoncons::basic_json<StringT, Alloc>::name_value_pair’ [-fpermissive]
typedef member_type name_value_pair;
^
In file included from /home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons/json.hpp:19:0,
from /home/max/big/src/jsoncons-git/jsoncons/test_suite/src/json_construction_tests.cpp:10:
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons/json_structures.hpp:260:7: error: changes meaning of ‘name_value_pair’ from ‘class jsoncons::name_value_pair<StringT, jsoncons::basic_json<StringT, Alloc> >’ [-fpermissive]
class name_value_pair
^
CMakeFiles/jsoncons_tests.dir/build.make:54: set di istruzioni per l'obiettivo "CMakeFiles/jsoncons_tests.dir/home/max/big/src/jsoncons-git/jsoncons/test_suite/src/json_construction_tests.cpp.o" non riuscito
make[2]: *** [CMakeFiles/jsoncons_tests.dir/home/max/big/src/jsoncons-git/jsoncons/test_suite/src/json_construction_tests.cpp.o] Errore 1
CMakeFiles/Makefile2:60: set di istruzioni per l'obiettivo "CMakeFiles/jsoncons_tests.dir/all" non riuscito
make[1]: *** [CMakeFiles/jsoncons_tests.dir/all] Errore 2
Makefile:76: set di istruzioni per l'obiettivo "all" non riuscito
make: *** [all] Errore 2
--- end output ---

Compiler warnings

Hi,

Could you please fix the warnings below? g++ version is 4.9.1, flags --std=c++14 -Wall.

jsoncons/src/jsoncons/json2.hpp:1154:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             if (result != size)
                        ^
In file included from jsoncons/src/jsoncons/json_reader.hpp:22:0,
                 from jsoncons/src/jsoncons/json2.hpp:25,
                 from jsoncons/src/jsoncons/json.hpp:12,
                 from src/feed.cpp:5:
jsoncons/src/jsoncons/json_parser.hpp: In instantiation of ‘jsoncons::basic_json_parser<Char>::basic_json_parser(jsoncons::basic_json_input_handler<Char>&) [with Char = char]’:
jsoncons/src/jsoncons/json2.hpp:1160:51:   required from ‘static jsoncons::basic_json<Char, Alloc> jsoncons::basic_json<Char, Alloc>::parse_file(const string&) [with Char = char;
 Alloc = std::allocator<void>; std::string = std::basic_string<char>]’
src/feed.cpp:87:64:   required from here
jsoncons/src/jsoncons/json_parser.hpp:1552:10: warning: ‘jsoncons::basic_json_parser<char>::is_negative_’ will be initialized after [-Wreorder]
     bool is_negative_;
          ^
jsoncons/src/jsoncons/json_parser.hpp:1549:14: warning:   ‘uint32_t jsoncons::basic_json_parser<char>::cp_’ [-Wreorder]
     uint32_t cp_;
              ^
In file included from jsoncons/src/jsoncons/json_reader.hpp:22:0,
                 from jsoncons/src/jsoncons/json2.hpp:25,
                 from jsoncons/src/jsoncons/json.hpp:12,
                 from src/feed.cpp:5:
jsoncons/src/jsoncons/json_parser.hpp:87:5: warning:   when initialized here [-Wreorder]
     basic_json_parser(basic_json_input_handler<Char>& handler)
     ^
In file included from git/jsoncons/src/jsoncons/json_reader.hpp:22:0,
                 from jsoncons/src/jsoncons/json2.hpp:25,
                 from jsoncons/src/jsoncons/json.hpp:12,
                 from src/feed.cpp:5:
jsoncons/src/jsoncons/json_parser.hpp: In instantiation of ‘void jsoncons::basic_json_parser<Char>::parse(const Char*, size_t, size_t) [with Char = char; size_t = long unsigned i
nt]’:
jsoncons/src/jsoncons/json2.hpp:1162:13:   required from ‘static jsoncons::basic_json<Char, Alloc> jsoncons::basic_json<Char, Alloc>::parse_file(const string&) [with Char = char;
 Alloc = std::allocator<void>; std::string = std::basic_string<char>]’
src/feed.cpp:87:64:   required from here
jsoncons/src/jsoncons/json_parser.hpp:202:13: warning: enumeration value ‘done’ not handled in switch [-Wswitch]
             switch (state_)
             ^

Compilation error

Hi,

Could you please fix compilation error:

ext/jsoncons/src/jsoncons/json_structures.hpp:1034:48: error: ‘s’ was not declared in this scope
equals_pred<value_type,char_type> comp(s, length);
^

ext/jsoncons/src/jsoncons/json_structures.hpp:1034:51: error: ‘length’ was not declared in this scope
equals_pred<value_type,char_type> comp(s, length);

error: declaration of ‘typedef ...

Second error compiling the test suite.
There is a problematic typedef definition in jsoncons/json.hpp:2736

typedef member_type name_value_pair

I don't know if it's the correct solution but, deleting the line, the compilation continue.

I transcrive, below, the output

--- begin output ---
[ 3%] Building CXX object CMakeFiles/jsoncons_tests.dir/home/max/big/src/jsoncons-git/jsoncons/test_suite/src/json_construction_tests.cpp.o
In file included from /home/max/big/src/jsoncons-git/jsoncons/test_suite/src/json_construction_tests.cpp:10:0:
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons/json.hpp:2736:25: error: declaration of ‘typedef jsoncons::basic_json<StringT, Alloc>::member_type jsoncons::basic_json<StringT, Alloc>::name_value_pair’ [-fpermissive]
typedef member_type name_value_pair;
^
In file included from /home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons/json.hpp:19:0,
from /home/max/big/src/jsoncons-git/jsoncons/test_suite/src/json_construction_tests.cpp:10:
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons/json_structures.hpp:260:7: error: changes meaning of ‘name_value_pair’ from ‘class jsoncons::name_value_pair<StringT, jsoncons::basic_json<StringT, Alloc> >’ [-fpermissive]
class name_value_pair
^
CMakeFiles/jsoncons_tests.dir/build.make:54: set di istruzioni per l'obiettivo "CMakeFiles/jsoncons_tests.dir/home/max/big/src/jsoncons-git/jsoncons/test_suite/src/json_construction_tests.cpp.o" non riuscito
make[2]: *** [CMakeFiles/jsoncons_tests.dir/home/max/big/src/jsoncons-git/jsoncons/test_suite/src/json_construction_tests.cpp.o] Errore 1
CMakeFiles/Makefile2:60: set di istruzioni per l'obiettivo "CMakeFiles/jsoncons_tests.dir/all" non riuscito
make[1]: *** [CMakeFiles/jsoncons_tests.dir/all] Errore 2
Makefile:76: set di istruzioni per l'obiettivo "all" non riuscito
make: *** [all] Errore 2
--- end output ---

json query evaluator helper function to detect single match

Is it possible to implement a helper function to test if a query result matched a single non array value?
For instance, I want json_query(json, "$") to return json and not [json].

It will be as simple as

//jsonpath_evaluator
bool is_strict_single_match() const
{
    if (stack_.size() != 1)
        return false;

    cjson_ptr p = stack_.back()[0];

    return p->type() != value_types::array_t;
}

Support for VS2008

So far I have played with a lot of C++ libraries and this is my favorite due to the nice API and the fact that it is header-only.

I'm not sure whether I am just missing something, but you can't use this library with MSVC2008, right? I have a C++ library for which one of the wrappers I need is python 2.7, which must be compiled with MSVC2008 since python 2.7 is. Would it be possible to make MSVC2008 work with jsoncons? Otherwise I will have to use another less awesome library. How about a VS2008 compiler flag to allow for some backwards compatibility?

jsoncons::json::parse_string("null") calls back() on an std::empty vector

If you call jsoncons::json::parse_string("null"), value(null_type(), ...) is called on the handler without begin_object() or begin_array() being called first. In the case of json_deserializer, this results in stack_.back() being called without anything being on the stack.

I imagine check_value_precondition() should be returning an error code if there isn't an object or an array on the parse stack.

-fpermissive errors

Hey using jsoncons I get the following -fpermissive error. I could disable it locally, but ideally this could be fixed upstream.

Thanks!

jsoncons/src/jsoncons/json.hpp:2825:25: error: declaration of ‘typedef jsoncons::basic_json<StringT, Alloc>::member_type jsoncons::basic_json<StringT, Alloc>::name_value_pair’ [-fpermissive]
     typedef member_type name_value_pair;
                         ^
jsoncons/src/jsoncons/json_structures.hpp:250:7: error: changes meaning of ‘name_value_pair’ from ‘class jsoncons::name_value_pair<std::basic_string<typename StringT::value_type, std::char_traits<typename StringT::value_type>, typename std::allocator_traits<_Alloc>::rebind_alloc<typename StringT::value_type> >, jsoncons::basic_json<StringT, Alloc> >’ [-fpermissive]
 class name_value_pair
       ^

json_parser_errc should not have the value 0

When jsoncons::json_parser_errc::unexpected_eof is stored as std::error_code, then it cannot be tested in the usual way: std::error_code::operator bool

I suggest increasing all jsoncons::json_parser_errc values by 1 and returning null instead of throwing:

static basic_json parse(const string_type& s, basic_parse_error_handler<char_type>& err_handler)
{
    basic_json_deserializer<basic_json<StringT, Alloc>> handler;
    basic_json_parser<char_type> parser(handler,err_handler);
    parser.begin_parse();
    parser.parse(s.data(),0,s.length());
    parser.end_parse();
    parser.check_done(s.data(),parser.index(),s.length());
    if (!handler.is_valid())
    {
        //JSONCONS_THROW_EXCEPTION(std::runtime_error,"Failed to parse json string");
        return null;
    }
    return handler.get_result();
}

Objects are considered equal if they have the same member names

The implementation of operator== for json_object means that two json objects are considered equal if the set of member names is the same for both objects; the values are not checked. So
{ "foo": 1 }
and
{ "foo": "bar" }
would be considered equal. This is certainly not what I would expect.

gcc linker reports undefined reference

Hi,

Could you please suggest if the library really missing implementation of assign method, or this is some kind of mistake on my side?

(.text._ZN5tracy8tracer_tILNS_11log_level_tE1ELNS_12write_mode_tE83ELNS_11timestamp_tE87EEC2ERKSsRKN8jsoncons10basic_jsonIcSaIvEEE[_ZN5tracy8tracer_tILNS_11log_level_tE1ELNS_12write_mode_tE83ELNS_11timestamp_tE87EEC5ERKSsRKN8jsoncons10basic_jsonIcSaIvEEE]+0xeb): undefined reference to `jsoncons::json_type_traits<char, std::allocator<void>, tracy::log_level_t>::assign(jsoncons::basic_json<char, std::allocator<void> >&, tracy::log_level_t)'

Thanks in advance,
Alexey

jsoncons-0.97.2: Compilation error with Visual Studio Professional 2015.

Visual Studio 2013 and Visual Studio 2015 with Platform Toolset "Visual Studio 2013 (v120)" compile the code successfully.

The issue appears if to switch to Visual Studio 2015 (v140) Platform Toolset.

Here is reported error:

1>c:\test\jsoncons\parse_error_handler.hpp(188): error C2694: 'const char *jsoncons::json_parser_category_impl::name(void) const': overriding virtual function has less restrictive exception specification than base class virtual member function 'const char *std::error_category::name(void) noexcept const'
1> c:\test\jsoncons\parse_error_handler.hpp(188): note: see declaration of 'jsoncons::json_parser_category_impl::name'
1> c:\program files (x86)\microsoft visual studio 14.0\vc\include\system_error(167): note: see declaration of 'std::error_category::name'

Compilation error

Hi,

first time using the library with Visual Studio 2013.
I try to use wjson (UTF16).

in file json.hpp:
...

   template <typename T>
    basic_json(T val)
        : var_(null_type())
    {
==>        json_type_traits<value_type,T>::assign(*this,val);    <==
    }

Here is the error I get:
189 error C3861: 'assign': identifier not found
188 error C2039: 'assign': is not a member of 'jsoncons::json_type_traits<jsoncons::basic_json<wchar_t, std::allocator>, T>'

Any idea where to search for. I take a look a json_type_traits.hpp and the wchar_t seems to be define correctly with a corresponding assign method:

template<class JsonT>
class json_type_traits<JsonT, wchar_t>
{
public:
    static bool is(const JsonT& rhs) JSONCONS_NOEXCEPT
    {
        if (rhs.is_integer())
        {
            return rhs.as_integer() >= std::numeric_limits<wchar_t>::min JSONCONS_NO_MACRO_EXP() && rhs.as_integer() <= std::numeric_limits<wchar_t>::max JSONCONS_NO_MACRO_EXP();
        }
        else if (rhs.is_uinteger())
        {
            return rhs.as_uinteger() <= static_cast<unsigned long long>(std::numeric_limits<wchar_t>::max JSONCONS_NO_MACRO_EXP());
        }
        else
        {
            return false;
        }
    }
    static wchar_t as(const JsonT& rhs)
    {
        return static_cast<wchar_t>(rhs.as_integer());
    }
    static void assign(JsonT& lhs, wchar_t ch)
    {
        lhs.assign_integer(ch);
    }
};

thanks for your help.

Minor errors in example code.

Not a big deal, but I noticed the following are missing in the using declarations in the README.md. Other than those minor issues, the example code works as described. Nice work.

using std::cerr;
using jsoncons::json_exception;

warning: enumeration values not handled in switches

Warning compiling with clang++ the test suite.
There are some switches, in jsoncons_ext/csv/csv_reader.hpp, that do not handle all enum cases.
The first is in line 200 and do not handle the cases "modes::header" and "modes::done".
The second is in line 214 and do not handle the case "modes::done".
The third is in line 453 and do not handle 13 cases (all cases except "states::unquoted_string" and "states::escaped_value").
The fourth is in line 473 and do not handle the case "modes::done".

--- begin output ---
[ 96%] Building CXX object CMakeFiles/jsoncons_tests.dir/home/max/big/src/jsoncons-git/jsoncons/test_suite/src/csv_tests.cpp.o
In file included from /home/max/big/src/jsoncons-git/jsoncons/test_suite/src/csv_tests.cpp:10:
In file included from /home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/csv/csv_reader.hpp:20:
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/csv/csv_parser.hpp:214:17: warning: enumeration value 'done' not handled in switch [-Wswitch]
switch (stack_[top_])
^
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/csv/csv_parser.hpp:339:21: note: in instantiation of member function 'jsoncons::csv::basic_csv_parser::after_record' requested here
after_record();
^
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/csv/csv_reader.hpp:135:25: note: in instantiation of member function 'jsoncons::csv::basic_csv_parser::parse' requested here
parser_.parse(buffer_.data(),index_,buffer_length_);
^
/home/max/big/src/jsoncons-git/jsoncons/test_suite/src/csv_tests.cpp:34:12: note: in instantiation of member function 'jsoncons::csv::basic_csv_reader::read' requested here
reader.read();
^
In file included from /home/max/big/src/jsoncons-git/jsoncons/test_suite/src/csv_tests.cpp:10:
In file included from /home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/csv/csv_reader.hpp:20:
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/csv/csv_parser.hpp:200:21: warning: enumeration values 'done' and 'header' not handled in switch [-Wswitch]
switch (stack_[top_])
^
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/csv/csv_parser.hpp:356:25: note: in instantiation of member function 'jsoncons::csv::basic_csv_parser::before_record' requested here
before_record();
^
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/csv/csv_reader.hpp:135:25: note: in instantiation of member function 'jsoncons::csv::basic_csv_parser::parse' requested here
parser_.parse(buffer_.data(),index_,buffer_length_);
^
/home/max/big/src/jsoncons-git/jsoncons/test_suite/src/csv_tests.cpp:34:12: note: in instantiation of member function 'jsoncons::csv::basic_csv_reader::read' requested here
reader.read();
^
In file included from /home/max/big/src/jsoncons-git/jsoncons/test_suite/src/csv_tests.cpp:10:
In file included from /home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/csv/csv_reader.hpp:20:
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/csv/csv_parser.hpp:453:17: warning: 13 enumeration values not handled in switch: 'start', 'comment', 'expect_value'... [-Wswitch]
switch (state_)
^
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/csv/csv_reader.hpp:139:17: note: in instantiation of member function 'jsoncons::csv::basic_csv_parser::end_parse' requested here
parser_.end_parse();
^
/home/max/big/src/jsoncons-git/jsoncons/test_suite/src/csv_tests.cpp:34:12: note: in instantiation of member function 'jsoncons::csv::basic_csv_reader::read' requested here
reader.read();
^
In file included from /home/max/big/src/jsoncons-git/jsoncons/test_suite/src/csv_tests.cpp:10:
In file included from /home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/csv/csv_reader.hpp:20:
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/csv/csv_parser.hpp:473:17: warning: enumeration value 'done' not handled in switch [-Wswitch]
switch (stack_[top_])
^
4 warnings generated.
--- end output ---

error: call of overloaded ‘make_array(int, int)’ is ambiguous

Another compiling line 159 of test_suite/src/json_array_tests.cpp

basic_json<std::string,std::allocator<char>> a = basic_json<std::string,std::allocator<char>>::make_array<1>(10,0);

According to my compiler, there are 2 version of make_array<>(), from jsoncons/json.hpp, that are applicable:

  1. from line 1591

template <size_t dim, class T>
static typename std::enable_if<dim==1,basic_json>::type make_array(size_t n, const T& val, const Alloc& allocator = Alloc())

  1. from line 1597

template <size_t dim, typename... Args>
static basic_json make_array(size_t n, Args... args)

I'm not sure to have understand the rationale, but I suppose that the second version is intended to operate only when dim > 1.

In this case, a solution can be the attached

patch-6.txt

I transcribe, below, the output

--- begin output ---
[ 3%] Building CXX object CMakeFiles/jsoncons_tests.dir/home/max/big/src/jsoncons-git/jsoncons/test_suite/src/json_array_tests.cpp.o
/home/max/big/src/jsoncons-git/jsoncons/test_suite/src/json_array_tests.cpp: In member function ‘void json_array_test_suite::test_one_dim_array::test_method()’:
/home/max/big/src/jsoncons-git/jsoncons/test_suite/src/json_array_tests.cpp:159:118: error: call of overloaded ‘make_array(int, int)’ is ambiguous
basic_jsonstd::string,std::allocator a = basic_jsonstd::string,std::allocator::make_array<1>(10,0);
^
/home/max/big/src/jsoncons-git/jsoncons/test_suite/src/json_array_tests.cpp:159:118: note: candidates are:
In file included from /home/max/big/src/jsoncons-git/jsoncons/test_suite/src/json_array_tests.cpp:10:0:
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons/json.hpp:1592:61: note: static typename std::enable_if<(dim == 1), jsoncons::basic_json<StringT, Alloc> >::type jsoncons::basic_json<StringT, Alloc>::make_array(size_t, const T&, const Alloc&) [with long unsigned int dim = 1ul; T = int; StringT = std::basic_string; Alloc = std::allocator; typename std::enable_if<(dim == 1), jsoncons::basic_json<StringT, Alloc> >::type = jsoncons::basic_jsonstd::basic_string<char, std::allocator >; size_t = long unsigned int]
static typename std::enable_if<dim==1,basic_json>::type make_array(size_t n, const T& val, const Alloc& allocator = Alloc())
^
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons/json.hpp:1598:23: note: static jsoncons::basic_json<StringT, Alloc> jsoncons::basic_json<StringT, Alloc>::make_array(size_t, Args ...) [with long unsigned int dim = 1ul; Args = {int}; StringT = std::basic_string; Alloc = std::allocator; size_t = long unsigned int]
static basic_json make_array(size_t n, Args... args)
^
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons/json.hpp: In instantiation of ‘static jsoncons::basic_json<StringT, Alloc> jsoncons::basic_json<StringT, Alloc>::make_array(size_t, Args ...) [with long unsigned int dim = 2ul; Args = {int, int}; StringT = std::basic_string; Alloc = std::allocator; size_t = long unsigned int]’:
/home/max/big/src/jsoncons-git/jsoncons/test_suite/src/json_array_tests.cpp:175:39: required from here
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons/json.hpp:1602:36: error: call of overloaded ‘make_array(int&, int&)’ is ambiguous
basic_json val = make_array(args...);
^
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons/json.hpp:1602:36: note: candidates are:
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons/json.hpp:1592:61: note: static typename std::enable_if<(dim == 1), jsoncons::basic_json<StringT, Alloc> >::type jsoncons::basic_json<StringT, Alloc>::make_array(size_t, const T&, const Alloc&) [with long unsigned int dim = 1ul; T = int; StringT = std::basic_string; Alloc = std::allocator; typename std::enable_if<(dim == 1), jsoncons::basic_json<StringT, Alloc> >::type = jsoncons::basic_jsonstd::basic_string<char, std::allocator >; size_t = long unsigned int]
static typename std::enable_if<dim==1,basic_json>::type make_array(size_t n, const T& val, const Alloc& allocator = Alloc())
^
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons/json.hpp:1598:23: note: static jsoncons::basic_json<StringT, Alloc> jsoncons::basic_json<StringT, Alloc>::make_array(size_t, Args ...) [with long unsigned int dim = 1ul; Args = {int}; StringT = std::basic_string; Alloc = std::allocator; size_t = long unsigned int]
static basic_json make_array(size_t n, Args... args)
^
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons/json.hpp:1606:32: error: call of overloaded ‘make_array(int&, int&)’ is ambiguous
val[i] = make_array(args...);
^
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons/json.hpp:1606:32: note: candidates are:
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons/json.hpp:1592:61: note: static typename std::enable_if<(dim == 1), jsoncons::basic_json<StringT, Alloc> >::type jsoncons::basic_json<StringT, Alloc>::make_array(size_t, const T&, const Alloc&) [with long unsigned int dim = 1ul; T = int; StringT = std::basic_string; Alloc = std::allocator; typename std::enable_if<(dim == 1), jsoncons::basic_json<StringT, Alloc> >::type = jsoncons::basic_jsonstd::basic_string<char, std::allocator >; size_t = long unsigned int]
static typename std::enable_if<dim==1,basic_json>::type make_array(size_t n, const T& val, const Alloc& allocator = Alloc())
^
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons/json.hpp:1598:23: note: static jsoncons::basic_json<StringT, Alloc> jsoncons::basic_json<StringT, Alloc>::make_array(size_t, Args ...) [with long unsigned int dim = 1ul; Args = {int}; StringT = std::basic_string; Alloc = std::allocator; size_t = long unsigned int]
static basic_json make_array(size_t n, Args... args)
^
CMakeFiles/jsoncons_tests.dir/build.make:445: set di istruzioni per l'obiettivo "CMakeFiles/jsoncons_tests.dir/home/max/big/src/jsoncons-git/jsoncons/test_suite/src/json_array_tests.cpp.o" non riuscito
make[2]: *** [CMakeFiles/jsoncons_tests.dir/home/max/big/src/jsoncons-git/jsoncons/test_suite/src/json_array_tests.cpp.o] Errore 1
CMakeFiles/Makefile2:60: set di istruzioni per l'obiettivo "CMakeFiles/jsoncons_tests.dir/all" non riuscito
make[1]: *** [CMakeFiles/jsoncons_tests.dir/all] Errore 2
Makefile:76: set di istruzioni per l'obiettivo "all" non riuscito
make: *** [all] Errore 2
--- end output ---

Performance issue due to memory allocations

Hi,

While creating an average json tree, I am finding that a big percentage of the time is spent doing memory allocations and deallocations :
malloc 36%
free 21%

It's on a good desktop PC on windows 7.
In that example, jsoncons::basic_json constructor takes 90% of the CPU, so those measurements are not coming from anywhere else.

Function Name Inclusive Samples Exclusive Samples Inclusive Samples % Exclusive Samples %
jsoncons::basic_json<char,std::allocator >::basic_json<char,std::allocator > 1,800 101 90.73 5.09

The time spent freeing is concerning, there's probably a lot of extra work being done?
Also, I am wondering if it wouldn't be beneficial to provide a way to pass its own allocator or to do some kind of pooling.

Any thoughts?
I am generating about 5MB of json in about 40s at the moment, I think it's a bit too slow. I would expect a second or so.

Here's the sample code I am using:

json * createInstance(const json &type, bool isArrayElement = false)
{
    json *instance = NULL;

    std::string typeDef = type.as_string();

    if (type.is<json::object>())
    {
        std::string typeName0 = type["type"].as_string();

        const json *resolvedType = &type;
        bool isArray = false;
        int arrayDefaultSize = 1;

        if (type.has_member("type"))
        {
            if (isArrayElement == false && type.has_member("array"))
            {
                isArray = type["array"].as_bool();
            }
            if (type.has_member("array_default_size"))
            {
                arrayDefaultSize = type["array_default_size"].as_int();
            }

            std::string typeName = type["type"].as_string();
            TypesMap::iterator it = DataBlockImpl::_types.find(typeName);
            if (it != DataBlockImpl::_types.end())
            {
                resolvedType = it->second;
            }
        }

        if (isArray)
        {
            //create an object with "name", "type" and "array"
            instance = new json;
            for (auto it = type.begin_members(); it != type.end_members(); ++it)
            {
                (*instance)[it->name()] = std::move(*createInstance(it->value()));
            }
            //add a json array to the object
            json *elements = new json(json::an_array);
            for (int i = 0; i < arrayDefaultSize+1; i++)
            {
                json *element = createInstance(type,true);
                element->remove_member(std::string("array"));
                element->remove_member(std::string("array_default_size"));

                //name all the elements with their position in the array
                char buffer[64];
                sprintf(buffer, "%i", i-1); //item -1 is the template used to resize
                (*element)["name"] = std::string(buffer);

                elements->add(std::move(*element));
            }
            (*instance)["elements"] = std::move(*elements);
        }
        else
        {
            instance = new json;
            for (auto it = resolvedType->begin_members(); it != resolvedType->end_members(); ++it)
            {
                (*instance)[it->name()] = std::move(*createInstance(it->value()));
            }
            if (resolvedType != &type)
            {
                //we have resolved a type, we need to replace the struct type name by the name of the proxy
                (*instance)["struct"] = true;
                (*instance)["type"] = (*instance)["name"].as_string();
                (*instance)["name"] = type["name"].as_string();
                if (type.has_member("tags"))
                    (*instance)["tags"] = type["tags"];
            }
        }
    }
    else if (type.is<json::array>())
    {
        instance = new json(json::an_array);
        for (auto it = type.begin_elements(); it != type.end_elements(); ++it)
        {
            instance->add(std::move(*createInstance(*it)));
        }
    }
    else
    {
        instance = new json(type);
    }
    return instance;
}

error in query

We realized error in json_query.

Query $..book[(@.length-1)] returns wrong results on test file json.zip

It should return two last books, but returns two second ones.

We expect:
[{
'category' => "fiction"
'author' => "J. R. R. Tolkien"
'title' => "The Lord of the Rings"
'isbn' => "0-395-19395-8"
'price' => "22.99"
},
[
'category' => "fiction"
'author' => "Rotov K.K."
'title' => "The Lord of the Rings"
'isbn' => "0-395-19395-8"
'price' => "22.99"
}]

But we get:
[{
"category": "fiction",
"author": "Evelyn Waugh",
"title": "Sword of Honour",
"price": 12.99
},
{
"category": "fiction",
"author": "Tretyakovskiy R",
"title": "Sword of Honour",
"price": 12.99
}]

Undeclared identifiers

Hi, I want to evaluate jsoncons for my latest project, but as I started using it, I directly faced problems with the latest source from Github.
So hopefully it is known and I do not make any stupid mistake :)

By the way, the last version that compiles for me is the 0.98.2.1. Since 0.98.3 it is not working anymore :(

See the compile output for more details:

23:13:56: Running steps for project memo...
23:13:56: Configuration unchanged, skipping qmake step.
23:13:56: Starting: "/usr/bin/make"
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -c -pipe -g -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk -std=c++11 -stdlib=libc++ -mmacosx-version-min=10.7 -Wall -W -fPIC -I../../memo -I. -I/usr/local/include -I../../devlibs/jsoncons/src -I/usr/local/Cellar/qt5/5.5.1_2/mkspecs/macx-clang -o main.o ../src/main.cpp
In file included from ../src/main.cpp:30:
In file included from ../src/assetmanager.h:5:
In file included from ../../devlibs/jsoncons/src/jsoncons/json.hpp:10:
In file included from ../../devlibs/jsoncons/src/jsoncons/json1.hpp:20:
In file included from ../../devlibs/jsoncons/src/jsoncons/json_structures.hpp:20:
In file included from ../../devlibs/jsoncons/src/jsoncons/jsoncons.hpp:20:
In file included from ../../devlibs/jsoncons/src/jsoncons/jsoncons_io.hpp:22:
../../devlibs/jsoncons/src/jsoncons/ovectorstream.hpp:112:46: warning: unused parameter 'mode' [-Wunused-parameter]
std::ios_base::openmode mode = std::ios_base::out) override
^
../../devlibs/jsoncons/src/jsoncons/ovectorstream.hpp:161:60: warning: unused parameter 'mode' [-Wunused-parameter]
pos_type seekpos(pos_type pos, std::ios_base::openmode mode
^
../../devlibs/jsoncons/src/jsoncons/ovectorstream.hpp:200:16: error: use of undeclared identifier 'pptr'
return pptr() - pbase();
^
../../devlibs/jsoncons/src/jsoncons/ovectorstream.hpp:200:25: error: use of undeclared identifier 'pbase'
return pptr() - pbase();
^
../../devlibs/jsoncons/src/jsoncons/ovectorstream.hpp:206:9: error: use of undeclared identifier 'pubimbue'
pubimbue(loc);
^
../../devlibs/jsoncons/src/jsoncons/ovectorstream.hpp:211:9: error: use of undeclared identifier 'clear'
clear();
^
../../devlibs/jsoncons/src/jsoncons/ovectorstream.hpp:212:9: error: use of undeclared identifier 'seekp'
seekp(0, std::ios::beg);
^
In file included from ../src/main.cpp:30:
In file included from ../src/assetmanager.h:5:
In file included from ../../devlibs/jsoncons/src/jsoncons/json.hpp:10:
In file included from ../../devlibs/jsoncons/src/jsoncons/json1.hpp:20:
../../devlibs/jsoncons/src/jsoncons/json_structures.hpp:236:44: error: redefinition of 'allocator_type'
typedef typename JsonT::allocator_type allocator_type;
^
../../devlibs/jsoncons/src/jsoncons/json_structures.hpp:234:44: note: previous definition is here
typedef typename JsonT::allocator_type allocator_type;
^
In file included from ../src/main.cpp:30:
In file included from ../src/assetmanager.h:5:
In file included from ../../devlibs/jsoncons/src/jsoncons/json.hpp:10:
In file included from ../../devlibs/jsoncons/src/jsoncons/json1.hpp:22:
../../devlibs/jsoncons/src/jsoncons/json_output_handler.hpp:201:31: warning: unused parameter 'name' [-Wunused-parameter]
void do_name(const CharT* name, size_t length) override
^
../../devlibs/jsoncons/src/jsoncons/json_output_handler.hpp:201:44: warning: unused parameter 'length' [-Wunused-parameter]
void do_name(const CharT* name, size_t length) override
^
../../devlibs/jsoncons/src/jsoncons/json_output_handler.hpp:225:47: warning: unused parameter 'length' [-Wunused-parameter]
void do_string_value(const CharT_, size_t length) override
^
In file included from ../src/main.cpp:30:
In file included from ../src/assetmanager.h:5:
In file included from ../../devlibs/jsoncons/src/jsoncons/json.hpp:10:
In file included from ../../devlibs/jsoncons/src/jsoncons/json1.hpp:25:
In file included from ../../devlibs/jsoncons/src/jsoncons/json_deserializer.hpp:17:
../../devlibs/jsoncons/src/jsoncons/json_input_handler.hpp:241:31: warning: unused parameter 'p' [-Wunused-parameter]
void do_name(const CharT_ p, size_t length, const basic_parsing_context&) override
^
../../devlibs/jsoncons/src/jsoncons/json_input_handler.hpp:241:41: warning: unused parameter 'length' [-Wunused-parameter]
void do_name(const CharT* p, size_t length, const basic_parsing_context&) override
^
../../devlibs/jsoncons/src/jsoncons/json_input_handler.hpp:249:47: warning: unused parameter 'length' [-Wunused-parameter]
void do_string_value(const CharT_, size_t length, const basic_parsing_context&) override
^
In file included from ../src/main.cpp:30:
In file included from ../src/assetmanager.h:5:
In file included from ../../devlibs/jsoncons/src/jsoncons/json.hpp:10:
In file included from ../../devlibs/jsoncons/src/jsoncons/json1.hpp:25:
../../devlibs/jsoncons/src/jsoncons/json_deserializer.hpp:114:66: warning: unused parameter 'context' [-Wunused-parameter]
void do_begin_object(const basic_parsing_context<char_type>& context) override
^
../../devlibs/jsoncons/src/jsoncons/json_deserializer.hpp:141:65: warning: unused parameter 'context' [-Wunused-parameter]
void do_begin_array(const basic_parsing_context<char_type>& context) override
^
In file included from ../src/main.cpp:30:
In file included from ../src/assetmanager.h:5:
In file included from ../../devlibs/jsoncons/src/jsoncons/json.hpp:10:
In file included from ../../devlibs/jsoncons/src/jsoncons/json1.hpp:26:
In file included from ../../devlibs/jsoncons/src/jsoncons/json_reader.hpp:20:
../../devlibs/jsoncons/src/jsoncons/parse_error_handler.hpp:132:69: warning: unused parameter 'context' [-Wunused-parameter]
const basic_parsing_context& context) throw (parse_exception)
^
../../devlibs/jsoncons/src/jsoncons/parse_error_handler.hpp:148:65: warning: unused parameter 'context' [-Wunused-parameter]
const basic_parsing_context& context) throw (parse_exception)
^
In file included from ../src/main.cpp:30:
In file included from ../src/assetmanager.h:5:
In file included from ../../devlibs/jsoncons/src/jsoncons/json.hpp:10:
../../devlibs/jsoncons/src/jsoncons/json1.hpp:39:35: error: use 'template' keyword to treat 'rebind_alloc' as a dependent template name
std::allocator_traits::rebind_alloc alloc(allocator);
^
template
../../devlibs/jsoncons/src/jsoncons/json1.hpp:39:47: error: expected ';' after expression
std::allocator_traits::rebind_alloc alloc(allocator);
^
;
../../devlibs/jsoncons/src/jsoncons/json1.hpp:43:18: error: use of undeclared identifier 'alloc'
T_ storage = alloc.allocate(1);
^
../../devlibs/jsoncons/src/jsoncons/json1.hpp:47:39: error: use 'template' keyword to treat 'rebind_traits' as a dependent template name
std::allocator_traits::rebind_traits::construct(alloc, storage, allocator);
^
template
../../devlibs/jsoncons/src/jsoncons/json1.hpp:47:67: error: use of undeclared identifier 'alloc'
std::allocator_traits::rebind_traits::construct(alloc, storage, allocator);
^
../../devlibs/jsoncons/src/jsoncons/json1.hpp:54:9: error: use of undeclared identifier 'alloc'
alloc.deallocate(storage,1);
^
../../devlibs/jsoncons/src/jsoncons/json1.hpp:64:35: error: use 'template' keyword to treat 'rebind_alloc' as a dependent template name
std::allocator_traits::rebind_alloc alloc(allocator);
^
template
../../devlibs/jsoncons/src/jsoncons/json1.hpp:64:47: error: expected ';' after expression
std::allocator_traits::rebind_alloc alloc(allocator);
^
;
../../devlibs/jsoncons/src/jsoncons/json1.hpp:68:18: error: use of undeclared identifier 'alloc'
T* storage = alloc.allocate(1);
^
../../devlibs/jsoncons/src/jsoncons/json1.hpp:72:39: error: use 'template' keyword to treat 'rebind_traits' as a dependent template name
std::allocator_traits::rebind_traits::construct(alloc, storage, std::forward(val), allocator);
^
template
../../devlibs/jsoncons/src/jsoncons/json1.hpp:72:67: error: use of undeclared identifier 'alloc'
std::allocator_traits::rebind_traits::construct(alloc, storage, std::forward(val), allocator);
^
../../devlibs/jsoncons/src/jsoncons/json1.hpp:79:9: error: use of undeclared identifier 'alloc'
alloc.deallocate(storage,1);
^
../../devlibs/jsoncons/src/jsoncons/json1.hpp:89:35: error: use 'template' keyword to treat 'rebind_alloc' as a dependent template name
std::allocator_traits::rebind_alloc alloc(allocator);
^
template
fatal error: too many errors emitted, stopping now [-ferror-limit=]
12 warnings and 20 errors generated.
make: *** [main.o] Error 1
23:13:57: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project memo (kit: GameDev)
When executing step "Make"
23:13:57: Elapsed time: 00:01.

json::parse stream missing return value

diff --git a/src/jsoncons/json.hpp b/src/jsoncons/json.hpp
index 50a0d87..0bef8b9 100644
--- a/src/jsoncons/json.hpp
+++ b/src/jsoncons/json.hpp
@@ -2773,11 +2773,11 @@ public:

     static basic_json parse(std::basic_istream<char_type>& is)
     {
-        parse_stream(is);
+        return parse_stream(is);
     }
     static basic_json parse(std::basic_istream<char_type>& is, basic_parse_error_handler<char_type>& err_handler)
     {
-        parse_stream(is,err_handler);
+        return parse_stream(is,err_handler);
     }

Is it possbile to have a non-alphabetic sort?

Firstly I think this software is great and the ability to have an xpath like facility is so useful.

Is there any way to prevent the alphabetic sort of the outputted JSON? Is there a way of retaining the original insertion order?

Thanks

error: ‘jsonpath_parser_errc’ was not declared in this scope

Third error compiling the test suite.
My compirer report that jsonpath_parser_errc in undeclared in jsoncons_ext/jsonpath/jsonpath_filter.hpp, line 74 (and a lot of other lines)

throw parse_exception(std::error_code(jsonpath_parser_errc::invalid_filter_unsupported_operator, jsonpath_error_category()),1,1);

I suppose that a possible solution could be the inclusion of jsonpath_error_category.hpp at the beginning of the file

`#include "jsoncons_ext/jsonpath/jsonpath_error_category.hpp"

I transcribe, below, the output

--- begin output ---
[ 3%] Building CXX object CMakeFiles/jsoncons_tests.dir/home/max/big/src/jsoncons-git/jsoncons/test_suite/src/jsonpath_filter_tests.cpp.o
In file included from /home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/json_query.hpp:17:0,
from /home/max/big/src/jsoncons-git/jsoncons/test_suite/src/jsonpath_filter_tests.cpp:15:
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/jsonpath_filter.hpp: In member function ‘virtual bool jsoncons::jsonpath::term::accept_single_node() const’:
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/jsonpath_filter.hpp:74:47: error: ‘jsonpath_parser_errc’ was not declared in this scope
throw parse_exception(std::error_code(jsonpath_parser_errc::invalid_filter_unsupported_operator, jsonpath_error_category()),1,1);
^
In file included from /home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/json_query.hpp:17:0,
from /home/max/big/src/jsoncons-git/jsoncons/test_suite/src/jsonpath_filter_tests.cpp:15:
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/jsonpath_filter.hpp:74:130: error: there are no arguments to ‘jsonpath_error_category’ that depend on a template parameter, so a declaration of ‘jsonpath_error_category’ must be available [-fpermissive]
throw parse_exception(std::error_code(jsonpath_parser_errc::invalid_filter_unsupported_operator, jsonpath_error_category()),1,1);
^
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/jsonpath_filter.hpp:74:130: note: (if you use ‘-fpermissive’, G++ will accept your code, but allowing the use of an undeclared name is deprecated)
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/jsonpath_filter.hpp: In member function ‘virtual JsonT jsoncons::jsonpath::term::evaluate_single_node() const’:
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/jsonpath_filter.hpp:78:47: error: ‘jsonpath_parser_errc’ was not declared in this scope
throw parse_exception(std::error_code(jsonpath_parser_errc::invalid_filter_unsupported_operator, jsonpath_error_category()),1,1);
^
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/jsonpath_filter.hpp:78:130: error: there are no arguments to ‘jsonpath_error_category’ that depend on a template parameter, so a declaration of ‘jsonpath_error_category’ must be available [-fpermissive]
throw parse_exception(std::error_code(jsonpath_parser_errc::invalid_filter_unsupported_operator, jsonpath_error_category()),1,1);
^
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/jsonpath_filter.hpp: In member function ‘virtual bool jsoncons::jsonpath::term::exclaim() const’:
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/jsonpath_filter.hpp:82:47: error: ‘jsonpath_parser_errc’ was not declared in this scope
throw parse_exception(std::error_code(jsonpath_parser_errc::invalid_filter_unsupported_operator, jsonpath_error_category()),1,1);
^
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/jsonpath_filter.hpp:82:130: error: there are no arguments to ‘jsonpath_error_category’ that depend on a template parameter, so a declaration of ‘jsonpath_error_category’ must be available [-fpermissive]
throw parse_exception(std::error_code(jsonpath_parser_errc::invalid_filter_unsupported_operator, jsonpath_error_category()),1,1);
^
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/jsonpath_filter.hpp: In member function ‘virtual bool jsoncons::jsonpath::term::eq(const jsoncons::jsonpath::term&) const’:
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/jsonpath_filter.hpp:86:47: error: ‘jsonpath_parser_errc’ was not declared in this scope
throw parse_exception(std::error_code(jsonpath_parser_errc::invalid_filter_unsupported_operator, jsonpath_error_category()),1,1);
^
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/jsonpath_filter.hpp:86:130: error: there are no arguments to ‘jsonpath_error_category’ that depend on a template parameter, so a declaration of ‘jsonpath_error_category’ must be available [-fpermissive]
throw parse_exception(std::error_code(jsonpath_parser_errc::invalid_filter_unsupported_operator, jsonpath_error_category()),1,1);
^
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/jsonpath_filter.hpp: In member function ‘virtual bool jsoncons::jsonpath::term::eq(const JsonT&) const’:
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/jsonpath_filter.hpp:90:47: error: ‘jsonpath_parser_errc’ was not declared in this scope
throw parse_exception(std::error_code(jsonpath_parser_errc::invalid_filter_unsupported_operator, jsonpath_error_category()),1,1);
^
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/jsonpath_filter.hpp:90:130: error: there are no arguments to ‘jsonpath_error_category’ that depend on a template parameter, so a declaration of ‘jsonpath_error_category’ must be available [-fpermissive]
throw parse_exception(std::error_code(jsonpath_parser_errc::invalid_filter_unsupported_operator, jsonpath_error_category()),1,1);
^
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/jsonpath_filter.hpp: In member function ‘virtual bool jsoncons::jsonpath::term::ne(const jsoncons::jsonpath::term&) const’:
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/jsonpath_filter.hpp:94:47: error: ‘jsonpath_parser_errc’ was not declared in this scope
throw parse_exception(std::error_code(jsonpath_parser_errc::invalid_filter_unsupported_operator, jsonpath_error_category()),1,1);
^
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/jsonpath_filter.hpp:94:130: error: there are no arguments to ‘jsonpath_error_category’ that depend on a template parameter, so a declaration of ‘jsonpath_error_category’ must be available [-fpermissive]
throw parse_exception(std::error_code(jsonpath_parser_errc::invalid_filter_unsupported_operator, jsonpath_error_category()),1,1);
^
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/jsonpath_filter.hpp: In member function ‘virtual bool jsoncons::jsonpath::term::ne(const JsonT&) const’:
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/jsonpath_filter.hpp:98:47: error: ‘jsonpath_parser_errc’ was not declared in this scope
throw parse_exception(std::error_code(jsonpath_parser_errc::invalid_filter_unsupported_operator, jsonpath_error_category()),1,1);
^
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/jsonpath_filter.hpp:98:130: error: there are no arguments to ‘jsonpath_error_category’ that depend on a template parameter, so a declaration of ‘jsonpath_error_category’ must be available [-fpermissive]
throw parse_exception(std::error_code(jsonpath_parser_errc::invalid_filter_unsupported_operator, jsonpath_error_category()),1,1);
^
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/jsonpath_filter.hpp: In member function ‘virtual bool jsoncons::jsonpath::term::regex(const jsoncons::jsonpath::term&) const’:
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/jsonpath_filter.hpp:102:47: error: ‘jsonpath_parser_errc’ was not declared in this scope
throw parse_exception(std::error_code(jsonpath_parser_errc::invalid_filter_unsupported_operator, jsonpath_error_category()),1,1);
^
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/jsonpath_filter.hpp:102:130: error: there are no arguments to ‘jsonpath_error_category’ that depend on a template parameter, so a declaration of ‘jsonpath_error_category’ must be available [-fpermissive]
throw parse_exception(std::error_code(jsonpath_parser_errc::invalid_filter_unsupported_operator, jsonpath_error_category()),1,1);
^
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/jsonpath_filter.hpp: In member function ‘virtual bool jsoncons::jsonpath::term::regex2(const string_type&) const’:
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/jsonpath_filter.hpp:106:47: error: ‘jsonpath_parser_errc’ was not declared in this scope
throw parse_exception(std::error_code(jsonpath_parser_errc::invalid_filter_unsupported_operator, jsonpath_error_category()),1,1);
^
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/jsonpath_filter.hpp:106:130: error: there are no arguments to ‘jsonpath_error_category’ that depend on a template parameter, so a declaration of ‘jsonpath_error_category’ must be available [-fpermissive]
throw parse_exception(std::error_code(jsonpath_parser_errc::invalid_filter_unsupported_operator, jsonpath_error_category()),1,1);
^
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/jsonpath_filter.hpp: In member function ‘virtual bool jsoncons::jsonpath::term::ampamp(const jsoncons::jsonpath::term&) const’:
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/jsonpath_filter.hpp:110:47: error: ‘jsonpath_parser_errc’ was not declared in this scope
throw parse_exception(std::error_code(jsonpath_parser_errc::invalid_filter_unsupported_operator, jsonpath_error_category()),1,1);
^
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/jsonpath_filter.hpp:110:130: error: there are no arguments to ‘jsonpath_error_category’ that depend on a template parameter, so a declaration of ‘jsonpath_error_category’ must be available [-fpermissive]
throw parse_exception(std::error_code(jsonpath_parser_errc::invalid_filter_unsupported_operator, jsonpath_error_category()),1,1);
^
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/jsonpath_filter.hpp: In member function ‘virtual bool jsoncons::jsonpath::term::ampamp(const JsonT&) const’:
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/jsonpath_filter.hpp:114:47: error: ‘jsonpath_parser_errc’ was not declared in this scope
throw parse_exception(std::error_code(jsonpath_parser_errc::invalid_filter_unsupported_operator, jsonpath_error_category()),1,1);
^
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/jsonpath_filter.hpp:114:130: error: there are no arguments to ‘jsonpath_error_category’ that depend on a template parameter, so a declaration of ‘jsonpath_error_category’ must be available [-fpermissive]
throw parse_exception(std::error_code(jsonpath_parser_errc::invalid_filter_unsupported_operator, jsonpath_error_category()),1,1);
^
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/jsonpath_filter.hpp: In member function ‘virtual bool jsoncons::jsonpath::term::pipepipe(const jsoncons::jsonpath::term&) const’:
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/jsonpath_filter.hpp:118:47: error: ‘jsonpath_parser_errc’ was not declared in this scope
throw parse_exception(std::error_code(jsonpath_parser_errc::invalid_filter_unsupported_operator, jsonpath_error_category()),1,1);
^
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/jsonpath_filter.hpp:118:130: error: there are no arguments to ‘jsonpath_error_category’ that depend on a template parameter, so a declaration of ‘jsonpath_error_category’ must be available [-fpermissive]
throw parse_exception(std::error_code(jsonpath_parser_errc::invalid_filter_unsupported_operator, jsonpath_error_category()),1,1);
^
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/jsonpath_filter.hpp: In member function ‘virtual bool jsoncons::jsonpath::term::pipepipe(const JsonT&) const’:
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/jsonpath_filter.hpp:122:47: error: ‘jsonpath_parser_errc’ was not declared in this scope
throw parse_exception(std::error_code(jsonpath_parser_errc::invalid_filter_unsupported_operator, jsonpath_error_category()),1,1);
^
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/jsonpath_filter.hpp:122:130: error: there are no arguments to ‘jsonpath_error_category’ that depend on a template parameter, so a declaration of ‘jsonpath_error_category’ must be available [-fpermissive]
throw parse_exception(std::error_code(jsonpath_parser_errc::invalid_filter_unsupported_operator, jsonpath_error_category()),1,1);
^
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/jsonpath_filter.hpp: In member function ‘virtual bool jsoncons::jsonpath::term::lt(const jsoncons::jsonpath::term&) const’:
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/jsonpath_filter.hpp:126:47: error: ‘jsonpath_parser_errc’ was not declared in this scope
throw parse_exception(std::error_code(jsonpath_parser_errc::invalid_filter_unsupported_operator, jsonpath_error_category()),1,1);
^
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/jsonpath_filter.hpp:126:130: error: there are no arguments to ‘jsonpath_error_category’ that depend on a template parameter, so a declaration of ‘jsonpath_error_category’ must be available [-fpermissive]
throw parse_exception(std::error_code(jsonpath_parser_errc::invalid_filter_unsupported_operator, jsonpath_error_category()),1,1);
^
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/jsonpath_filter.hpp: In member function ‘virtual bool jsoncons::jsonpath::term::lt(const JsonT&) const’:
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/jsonpath_filter.hpp:130:47: error: ‘jsonpath_parser_errc’ was not declared in this scope
throw parse_exception(std::error_code(jsonpath_parser_errc::invalid_filter_unsupported_operator, jsonpath_error_category()),1,1);
^
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/jsonpath_filter.hpp:130:130: error: there are no arguments to ‘jsonpath_error_category’ that depend on a template parameter, so a declaration of ‘jsonpath_error_category’ must be available [-fpermissive]
throw parse_exception(std::error_code(jsonpath_parser_errc::invalid_filter_unsupported_operator, jsonpath_error_category()),1,1);
^
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/jsonpath_filter.hpp: In member function ‘virtual bool jsoncons::jsonpath::term::gt(const jsoncons::jsonpath::term&) const’:
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/jsonpath_filter.hpp:134:47: error: ‘jsonpath_parser_errc’ was not declared in this scope
throw parse_exception(std::error_code(jsonpath_parser_errc::invalid_filter_unsupported_operator, jsonpath_error_category()),1,1);
^
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/jsonpath_filter.hpp:134:130: error: there are no arguments to ‘jsonpath_error_category’ that depend on a template parameter, so a declaration of ‘jsonpath_error_category’ must be available [-fpermissive]
throw parse_exception(std::error_code(jsonpath_parser_errc::invalid_filter_unsupported_operator, jsonpath_error_category()),1,1);
^
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/jsonpath_filter.hpp: In member function ‘virtual bool jsoncons::jsonpath::term::gt(const JsonT&) const’:
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/jsonpath_filter.hpp:138:47: error: ‘jsonpath_parser_errc’ was not declared in this scope
throw parse_exception(std::error_code(jsonpath_parser_errc::invalid_filter_unsupported_operator, jsonpath_error_category()),1,1);
^
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/jsonpath_filter.hpp:138:130: error: there are no arguments to ‘jsonpath_error_category’ that depend on a template parameter, so a declaration of ‘jsonpath_error_category’ must be available [-fpermissive]
throw parse_exception(std::error_code(jsonpath_parser_errc::invalid_filter_unsupported_operator, jsonpath_error_category()),1,1);
^
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/jsonpath_filter.hpp: In member function ‘virtual JsonT jsoncons::jsonpath::term::minus(const jsoncons::jsonpath::term&) const’:
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/jsonpath_filter.hpp:142:47: error: ‘jsonpath_parser_errc’ was not declared in this scope
throw parse_exception(std::error_code(jsonpath_parser_errc::invalid_filter_unsupported_operator, jsonpath_error_category()),1,1);
^
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/jsonpath_filter.hpp:142:130: error: there are no arguments to ‘jsonpath_error_category’ that depend on a template parameter, so a declaration of ‘jsonpath_error_category’ must be available [-fpermissive]
throw parse_exception(std::error_code(jsonpath_parser_errc::invalid_filter_unsupported_operator, jsonpath_error_category()),1,1);
^
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/jsonpath_filter.hpp: In member function ‘virtual JsonT jsoncons::jsonpath::term::minus(const JsonT&) const’:
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/jsonpath_filter.hpp:146:47: error: ‘jsonpath_parser_errc’ was not declared in this scope
throw parse_exception(std::error_code(jsonpath_parser_errc::invalid_filter_unsupported_operator, jsonpath_error_category()),1,1);
^
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/jsonpath_filter.hpp:146:130: error: there are no arguments to ‘jsonpath_error_category’ that depend on a template parameter, so a declaration of ‘jsonpath_error_category’ must be available [-fpermissive]
throw parse_exception(std::error_code(jsonpath_parser_errc::invalid_filter_unsupported_operator, jsonpath_error_category()),1,1);
^
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/jsonpath_filter.hpp: In member function ‘virtual JsonT jsoncons::jsonpath::term::unary_minus() const’:
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/jsonpath_filter.hpp:150:47: error: ‘jsonpath_parser_errc’ was not declared in this scope
throw parse_exception(std::error_code(jsonpath_parser_errc::invalid_filter_unsupported_operator, jsonpath_error_category()),1,1);
^
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/jsonpath_filter.hpp:150:130: error: there are no arguments to ‘jsonpath_error_category’ that depend on a template parameter, so a declaration of ‘jsonpath_error_category’ must be available [-fpermissive]
throw parse_exception(std::error_code(jsonpath_parser_errc::invalid_filter_unsupported_operator, jsonpath_error_category()),1,1);
^
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/jsonpath_filter.hpp: In member function ‘virtual JsonT jsoncons::jsonpath::term::plus(const jsoncons::jsonpath::term&) const’:
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/jsonpath_filter.hpp:154:47: error: ‘jsonpath_parser_errc’ was not declared in this scope
throw parse_exception(std::error_code(jsonpath_parser_errc::invalid_filter_unsupported_operator, jsonpath_error_category()),1,1);
^
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/jsonpath_filter.hpp:154:130: error: there are no arguments to ‘jsonpath_error_category’ that depend on a template parameter, so a declaration of ‘jsonpath_error_category’ must be available [-fpermissive]
throw parse_exception(std::error_code(jsonpath_parser_errc::invalid_filter_unsupported_operator, jsonpath_error_category()),1,1);
^
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/jsonpath_filter.hpp: In member function ‘virtual JsonT jsoncons::jsonpath::term::plus(const JsonT&) const’:
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/jsonpath_filter.hpp:158:47: error: ‘jsonpath_parser_errc’ was not declared in this scope
throw parse_exception(std::error_code(jsonpath_parser_errc::invalid_filter_unsupported_operator, jsonpath_error_category()),1,1);
^
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/jsonpath_filter.hpp:158:130: error: there are no arguments to ‘jsonpath_error_category’ that depend on a template parameter, so a declaration of ‘jsonpath_error_category’ must be available [-fpermissive]
throw parse_exception(std::error_code(jsonpath_parser_errc::invalid_filter_unsupported_operator, jsonpath_error_category()),1,1);
^
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/jsonpath_filter.hpp: At global scope:
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/jsonpath_filter.hpp:189:5: error: declaration of ‘std::shared_ptrjsoncons::jsonpath::term jsoncons::jsonpath::token::term()’ [-fpermissive]
}
^
In file included from /home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/json_query.hpp:17:0,
from /home/max/big/src/jsoncons-git/jsoncons/test_suite/src/jsonpath_filter_tests.cpp:15:
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/jsonpath_filter.hpp:63:7: error: changes meaning of ‘term’ from ‘class jsoncons::jsonpath::term’ [-fpermissive]
class term
^
In file included from /home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/json_query.hpp:17:0,
from /home/max/big/src/jsoncons-git/jsoncons/test_suite/src/jsonpath_filter_tests.cpp:15:
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/jsonpath_filter.hpp:897:5: error: declaration of ‘std::shared_ptrjsoncons::jsonpath::term jsoncons::jsonpath::jsonpath_filter_parser::term(jsoncons::jsonpath::token_stream&)’ [-fpermissive]
}
^
In file included from /home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/json_query.hpp:17:0,
from /home/max/big/src/jsoncons-git/jsoncons/test_suite/src/jsonpath_filter_tests.cpp:15:
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/jsonpath_filter.hpp:63:7: error: changes meaning of ‘term’ from ‘class jsoncons::jsonpath::term’ [-fpermissive]
class term
^
In file included from /home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/json_query.hpp:17:0,
from /home/max/big/src/jsoncons-git/jsoncons/test_suite/src/jsonpath_filter_tests.cpp:15:
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/jsonpath_filter.hpp: In member function ‘std::shared_ptrjsoncons::jsonpath::term jsoncons::jsonpath::jsonpath_filter_parser::primary(jsoncons::jsonpath::token_stream&)’:
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/jsonpath_filter.hpp:759:55: error: ‘jsonpath_parser_errc’ was not declared in this scope
throw parse_exception(std::error_code(jsonpath_parser_errc::invalid_filter_expected_right_brace, jsonpath_error_category()),line_,column_);
^
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/jsonpath_filter.hpp:759:138: error: there are no arguments to ‘jsonpath_error_category’ that depend on a template parameter, so a declaration of ‘jsonpath_error_category’ must be available [-fpermissive]
throw parse_exception(std::error_code(jsonpath_parser_errc::invalid_filter_expected_right_brace, jsonpath_error_category()),line_,column_);
^
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/jsonpath_filter.hpp:778:51: error: ‘jsonpath_parser_errc’ was not declared in this scope
throw parse_exception(std::error_code(jsonpath_parser_errc::invalid_filter_expected_primary, jsonpath_error_category()),line_,column_);
^
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/jsonpath_filter.hpp:778:130: error: there are no arguments to ‘jsonpath_error_category’ that depend on a template parameter, so a declaration of ‘jsonpath_error_category’ must be available [-fpermissive]
throw parse_exception(std::error_code(jsonpath_parser_errc::invalid_filter_expected_primary, jsonpath_error_category()),line_,column_);
^
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/jsonpath_filter.hpp: In member function ‘void jsoncons::jsonpath::jsonpath_filter_parser::parse(const char_type_, const char_type_)’:
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/jsonpath_filter.hpp:1056:59: error: ‘jsonpath_parser_errc’ was not declared in this scope
throw parse_exception(std::error_code(jsonpath_parser_errc::invalid_filter, jsonpath_error_category()),line_,column_);
^
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/jsonpath_filter.hpp:1056:121: error: there are no arguments to ‘jsonpath_error_category’ that depend on a template parameter, so a declaration of ‘jsonpath_error_category’ must be available [-fpermissive]
throw parse_exception(std::error_code(jsonpath_parser_errc::invalid_filter, jsonpath_error_category()),line_,column_);
^
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/jsonpath_filter.hpp:1337:59: error: ‘jsonpath_parser_errc’ was not declared in this scope
throw parse_exception(std::error_code(jsonpath_parser_errc::invalid_filter, jsonpath_error_category()),line_,column_);
^
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/jsonpath_filter.hpp:1337:121: error: there are no arguments to ‘jsonpath_error_category’ that depend on a template parameter, so a declaration of ‘jsonpath_error_category’ must be available [-fpermissive]
throw parse_exception(std::error_code(jsonpath_parser_errc::invalid_filter, jsonpath_error_category()),line_,column_);
^
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/jsonpath_filter.hpp:1365:59: error: ‘jsonpath_parser_errc’ was not declared in this scope
throw parse_exception(std::error_code(jsonpath_parser_errc::invalid_filter, jsonpath_error_category()),line_,column_);
^
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/jsonpath_filter.hpp:1365:121: error: there are no arguments to ‘jsonpath_error_category’ that depend on a template parameter, so a declaration of ‘jsonpath_error_category’ must be available [-fpermissive]
throw parse_exception(std::error_code(jsonpath_parser_errc::invalid_filter, jsonpath_error_category()),line_,column_);
^
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/jsonpath_filter.hpp:1439:59: error: ‘jsonpath_parser_errc’ was not declared in this scope
throw parse_exception(std::error_code(jsonpath_parser_errc::invalid_filter_expected_slash, jsonpath_error_category()),line_,column_);
^
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/jsonpath_filter.hpp:1439:136: error: there are no arguments to ‘jsonpath_error_category’ that depend on a template parameter, so a declaration of ‘jsonpath_error_category’ must be available [-fpermissive]
throw parse_exception(std::error_code(jsonpath_parser_errc::invalid_filter_expected_slash, jsonpath_error_category()),line_,column_);
^
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/jsonpath_filter.hpp:1487:51: error: ‘jsonpath_parser_errc’ was not declared in this scope
throw parse_exception(std::error_code(jsonpath_parser_errc::invalid_filter_unbalanced_paren, jsonpath_error_category()),line_,column_);
^
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/jsonpath_filter.hpp:1487:130: error: there are no arguments to ‘jsonpath_error_category’ that depend on a template parameter, so a declaration of ‘jsonpath_error_category’ must be available [-fpermissive]
throw parse_exception(std::error_code(jsonpath_parser_errc::invalid_filter_unbalanced_paren, jsonpath_error_category()),line_,column_);
^
In file included from /home/max/big/src/jsoncons-git/jsoncons/test_suite/src/jsonpath_filter_tests.cpp:15:0:
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/json_query.hpp: In instantiation of ‘JsonT jsoncons::jsonpath::json_query(const JsonT&, const typename JsonT::char_type_) [with JsonT = jsoncons::basic_jsonstd::basic_string<char, std::allocator >; typename JsonT::char_type = char]’:
/home/max/big/src/jsoncons-git/jsoncons/test_suite/src/jsonpath_filter_tests.cpp:102:58: required from here
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/json_query.hpp:87:90: error: no matching function for call to ‘json_query(const jsoncons::basic_jsonstd::basic_string<char, std::allocator >&, const char_type_&, std::size_t)’
return json_query(root,path,std::char_traits::length(path));
^
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/json_query.hpp:87:90: note: candidates are:
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/json_query.hpp:79:7: note: template JsonT jsoncons::jsonpath::json_query(const JsonT&, const typename JsonT::string_type&)
JsonT json_query(const JsonT& root, const typename JsonT::string_type& path)
^
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/json_query.hpp:79:7: note: template argument deduction/substitution failed:
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/json_query.hpp:87:90: note: candidate expects 2 arguments, 3 provided
return json_query(root,path,std::char_traits::length(path));
^
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/json_query.hpp:85:7: note: template JsonT jsoncons::jsonpath::json_query(const JsonT&, const typename JsonT::char_type_)
JsonT json_query(const JsonT& root, const typename JsonT::char_type_ path)
^
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/json_query.hpp:85:7: note: template argument deduction/substitution failed:
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/json_query.hpp:87:90: note: candidate expects 2 arguments, 3 provided
return json_query(root,path,std::char_traits::length(path));
^
CMakeFiles/jsoncons_tests.dir/build.make:238: set di istruzioni per l'obiettivo "CMakeFiles/jsoncons_tests.dir/home/max/big/src/jsoncons-git/jsoncons/test_suite/src/jsonpath_filter_tests.cpp.o" non riuscito
make[2]: *** [CMakeFiles/jsoncons_tests.dir/home/max/big/src/jsoncons-git/jsoncons/test_suite/src/jsonpath_filter_tests.cpp.o] Errore 1
CMakeFiles/Makefile2:60: set di istruzioni per l'obiettivo "CMakeFiles/jsoncons_tests.dir/all" non riuscito
make[1]: *** [CMakeFiles/jsoncons_tests.dir/all] Errore 2
Makefile:76: set di istruzioni per l'obiettivo "all" non riuscito
make: *** [all] Errore 2
--- end output ---

Inclusion of csv_reader header causes trouble

I am testing the cv_reader by using this code:
`#include

include

include

include "jsoncons/json.hpp"

include "jsoncons/json_deserializer.hpp"

include "jsoncons_ext/csv/csv_reader.hpp"

using jsoncons::json;
using jsoncons::pretty_print;
using jsoncons::output_format;
using jsoncons::json_deserializer;
using jsoncons::csv::csv_reader;
using jsoncons::csv::csv_parameters;

int main(int argc, char** argv) {

}
`
and I get this error:
json_filter.hpp:224:11: error: class 'jsoncons::basic_begin_end_json_filter' does not have any field named 'basic_json_filter'
: basic_json_filter(handler)
Is there any way to just avoid this?

problems with empty non-string values in csv conversion

Sorry again for my bad English.
I don't know if I doing something wrong, but... I have a problem with values imported for non-string types from empty csv fields.
I've written a minimal program to show the problem.

test-001.cpp.txt

In a nutshell...
Using the following csv content

"bool-f,int-f,float-f,string-f"
"\n,,,,"
"\ntrue,12,24.7,\"test string\","
"\n,,,,"

(a row of empty values, a row with valid values, another row with empty values) with the following data types string

"boolean,integer,float,string"

I obtain that:

  • the empty boolean field are ever ignored (like when "ignore_empty_values" is set)
  • the imported integer value for the first row is a randomic big number (different on every run of the program); for the third row is the same value (12) of the second row;
  • the imported float value for both first and third row is a randomic little value (different for the first and the third; different on every run of the program)

An example of output

[
{
"float-f":6.952914947851373e-310,
"int-f":140728565250248,
"string-f":""
},
{
"bool-f":true,
"float-f":24.7,
"int-f":12,
"string-f":"test string"
},
{
"float-f":9.99944203648299e-317,
"int-f":12,
"string-f":""
}
]

My environment is a Debian Jessie amd64 platform; I'm using clang++ 3.5.0 with the following compilation command

clang++ -o test-001.o -c -g -Wall -ansi -pedantic -std=c++11 -stdlib=libc++ -I. test-001.cpp

and the following linking command

clang++ -o test-001 -std=c++11 -stdlib=libc++ test-001.o

float_reader locale

Hi Daniel,

I notice another problem at runtime when generating json code...
I was able to see another issue with DebugDiag and I always got this stack trace at runtime :

LeakTrack+13277      
Test!_calloc_impl+5d   f:\dd\vctools\crt\crtw32\heap\calloc_impl.c @ 47   
Test!_calloc_crt+33   f:\dd\vctools\crt\crtw32\heap\crtheap.c @ 62 + e   
Test!_wcreate_locale+69   f:\dd\vctools\crt\crtw32\misc\wsetloca.c @ 337 + d   
Test!_create_locale+5a   f:\dd\vctools\crt\crtw32\misc\wsetloca.c @ 400 + c   
Test!jsoncons::basic_json_parser<wchar_t>::basic_json_parser<wchar_t>+b8   c:\projets\Test\commun\jsoncons\json_parser.hpp @ 168 + b8   
Test!jsoncons::operator>><jsoncons::basic_json<wchar_t,std::allocator<wchar_t> > >+91   c:\projets\Test\commun\jsoncons\json.hpp @ 3443 + e   
Test!l_set_user+2f   c:\projets\Test\Test\Test.cpp @ 8696 + 29   
Test!l_set+361   c:\projets\Test\Test\Test.h @ 925 + 1c   

The solution I found is to handle the _locale_t member in float_reader class in jsoncons_io.hpp:
If I'm not wrong, the _locale_t struct must be freed with a call to _free_locale
So I add a destructor to handle this case. I also add some restrictions to assignment and copy constructor because I don't want the class to be copied by the system and cause any kind of crash on the call to _free_locale(locale) later during execution.

 float_reader() : locale()
    {
        locale = _create_locale(LC_NUMERIC, "C");
    }
    ~float_reader() {
        _free_locale(locale);
    }

    float_reader(const float_reader& fr) = delete;
    float_reader& operator=(const float_reader& fr) = delete;

Thanks.

Unable to load/store float

Hi,

It is possible to write something like:

_config.get("mean", .0).as<double>();
_config["mean"] = 2.2; // double

But it looks like there is no similar functions accepting float:

_config.get("mean", .0).as<float>();
_config["mean"] = static_cast<float>(2.2);

Regards,
Alexey

jsonpath code does not work with GCC 4.8

std::regex isn't properly implemented in GCC 4.8 (it does basic string matching, but not regexes), so the jsoncons_ext/jsonpath stuff doesn't work (and the unit tests fail).

For me personally this isn't an issue - I only noticed a problem because of the unit tests. But it's something I wanted to make you aware of.

I see two options:

  1. Declare that jsonpath is unsupported on GCC 4.8 (and maybe disable those unit tests for GCC 4.8)
  2. Make use of boost::regex (which introduces a dependency on boost to use jsonpath)

Android does not support localeconv

Hi there
I use your library in a project that I cross compile for Android. I recently upgraded to a new version of your library which has locale support for floats.

Unfortunately Android does not have an implementation for "localeconv", so I had to comment that part out that it defaults to ".".

A macro can be used to do that I suppose.

Regards

json no longer works with boost::optional

The following code fails to compiler under GCC:

boost::optional<jsoncons::json> opt_json;
opt_json = jsoncons::json(jsoncons::json::an_object);

with the error

boost/optional/optional.hpp:346:8: error: no matching function for call to ‘jsoncons::basic_json<char, std::allocator<void> >::operator new(sizetype, void*)’
        new (m_storage.address()) internal_type(val) ;
note: candidate is:
jsoncons/json1.hpp:151:18: note: static void* jsoncons::basic_json<Char, Alloc>::operator new(std::size_t) [with Char = char; Alloc = std::allocator<void>; std::size_t = long unsigned int]
     static void* operator new(std::size_t) { return typename Alloc::template rebind<basic_json>::other().allocate(1); }
jsoncons/json1.hpp:151:18: note:   candidate expects 1 argument, 2 provided

error: declaration of ‘std::shared_ptr...

Fourth (and last, at the moment) error compiling the test suite.
My compiler give me an error in line 190 of jsoncons_ext/jsonpath/jsonpath_filter.hpp; declaration of std::shared_ptr<term<JsonT>> term(), class token

std::shared_ptr<term<JsonT>> term()
{
return term_;
}

If I understand correctly, there is a collision of term<> class with term() member function.

Same problem with the declaration of std::shared_ptr<term<JsonT>> term(token_stream<JsonT>& ts), lines 813-898.

I don't know which name change.

I transcribe, below, the output

--- begin output ---
[ 3%] Building CXX object CMakeFiles/jsoncons_tests.dir/home/max/big/src/jsoncons-git/jsoncons/test_suite/src/jsonpath_filter_tests.cpp.o
In file included from /home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/json_query.hpp:17:0,
from /home/max/big/src/jsoncons-git/jsoncons/test_suite/src/jsonpath_filter_tests.cpp:15:
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/jsonpath_filter.hpp:190:5: error: declaration of ‘std::shared_ptrjsoncons::jsonpath::term jsoncons::jsonpath::token::term()’ [-fpermissive]
}
^
In file included from /home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/json_query.hpp:17:0,
from /home/max/big/src/jsoncons-git/jsoncons/test_suite/src/jsonpath_filter_tests.cpp:15:
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/jsonpath_filter.hpp:64:7: error: changes meaning of ‘term’ from ‘class jsoncons::jsonpath::term’ [-fpermissive]
class term
^
In file included from /home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/json_query.hpp:17:0,
from /home/max/big/src/jsoncons-git/jsoncons/test_suite/src/jsonpath_filter_tests.cpp:15:
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/jsonpath_filter.hpp:898:5: error: declaration of ‘std::shared_ptrjsoncons::jsonpath::term jsoncons::jsonpath::jsonpath_filter_parser::term(jsoncons::jsonpath::token_stream&)’ [-fpermissive]
}
^
In file included from /home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/json_query.hpp:17:0,
from /home/max/big/src/jsoncons-git/jsoncons/test_suite/src/jsonpath_filter_tests.cpp:15:
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/jsonpath_filter.hpp:64:7: error: changes meaning of ‘term’ from ‘class jsoncons::jsonpath::term’ [-fpermissive]
class term
^
In file included from /home/max/big/src/jsoncons-git/jsoncons/test_suite/src/jsonpath_filter_tests.cpp:15:0:
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/json_query.hpp: In instantiation of ‘JsonT jsoncons::jsonpath::json_query(const JsonT&, const typename JsonT::char_type_) [with JsonT = jsoncons::basic_jsonstd::basic_string<char, std::allocator >; typename JsonT::char_type = char]’:
/home/max/big/src/jsoncons-git/jsoncons/test_suite/src/jsonpath_filter_tests.cpp:102:58: required from here
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/json_query.hpp:87:90: error: no matching function for call to ‘json_query(const jsoncons::basic_jsonstd::basic_string<char, std::allocator >&, const char_type_&, std::size_t)’
return json_query(root,path,std::char_traits::length(path));
^
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/json_query.hpp:87:90: note: candidates are:
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/json_query.hpp:79:7: note: template JsonT jsoncons::jsonpath::json_query(const JsonT&, const typename JsonT::string_type&)
JsonT json_query(const JsonT& root, const typename JsonT::string_type& path)
^
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/json_query.hpp:79:7: note: template argument deduction/substitution failed:
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/json_query.hpp:87:90: note: candidate expects 2 arguments, 3 provided
return json_query(root,path,std::char_traits::length(path));
^
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/json_query.hpp:85:7: note: template JsonT jsoncons::jsonpath::json_query(const JsonT&, const typename JsonT::char_type_)
JsonT json_query(const JsonT& root, const typename JsonT::char_type_ path)
^
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/json_query.hpp:85:7: note: template argument deduction/substitution failed:
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/json_query.hpp:87:90: note: candidate expects 2 arguments, 3 provided
return json_query(root,path,std::char_traits::length(path));
^
CMakeFiles/jsoncons_tests.dir/build.make:238: set di istruzioni per l'obiettivo "CMakeFiles/jsoncons_tests.dir/home/max/big/src/jsoncons-git/jsoncons/test_suite/src/jsonpath_filter_tests.cpp.o" non riuscito
make[2]: *** [CMakeFiles/jsoncons_tests.dir/home/max/big/src/jsoncons-git/jsoncons/test_suite/src/jsonpath_filter_tests.cpp.o] Errore 1
CMakeFiles/Makefile2:60: set di istruzioni per l'obiettivo "CMakeFiles/jsoncons_tests.dir/all" non riuscito
make[1]: *** [CMakeFiles/jsoncons_tests.dir/all] Errore 2
Makefile:76: set di istruzioni per l'obiettivo "all" non riuscito
make: *** [all] Errore 2
--- end output ---

warning: equality comparison result unused

Six warning of this type come from compiling the test suite with clang++.
The problem are in BOOST_AUTO_TEST_CASE(test_parse_primitive_pass), in test_suite/src/json_parse_tests.cpp, lines 88-103.
There are six lines of type
val == json::null_type();
where the comparision value is unused.
I suppose that the intention was
BOOST_CHECK(val == json::null_type());
or something similar.

--- begin output ---
/home/max/big/src/jsoncons-git/jsoncons/test_suite/src/json_parse_tests.cpp:92:9: warning: equality comparison result unused [-Wunused-comparison]
val == json::null_type();
~~~~^~~~~~~~~~~~~~~~~~~~
/home/max/big/src/jsoncons-git/jsoncons/test_suite/src/json_parse_tests.cpp:92:9: note: use '=' to turn this equality comparison into an assignment
val == json::null_type();
^~
=
/home/max/big/src/jsoncons-git/jsoncons/test_suite/src/json_parse_tests.cpp:94:9: warning: equality comparison result unused [-Wunused-comparison]
val == json(false);
~~~~^~~~~~~~~~~~~~
/home/max/big/src/jsoncons-git/jsoncons/test_suite/src/json_parse_tests.cpp:94:9: note: use '=' to turn this equality comparison into an assignment
val == json(false);
^~
=
/home/max/big/src/jsoncons-git/jsoncons/test_suite/src/json_parse_tests.cpp:96:9: warning: equality comparison result unused [-Wunused-comparison]
val == json(true);
~~~~^~~~~~~~~~~~~
/home/max/big/src/jsoncons-git/jsoncons/test_suite/src/json_parse_tests.cpp:96:9: note: use '=' to turn this equality comparison into an assignment
val == json(true);
^~
=
/home/max/big/src/jsoncons-git/jsoncons/test_suite/src/json_parse_tests.cpp:98:9: warning: equality comparison result unused [-Wunused-comparison]
val == json(10);
~~~~^~~~~~~~~~~
/home/max/big/src/jsoncons-git/jsoncons/test_suite/src/json_parse_tests.cpp:98:9: note: use '=' to turn this equality comparison into an assignment
val == json(10);
^~
=
/home/max/big/src/jsoncons-git/jsoncons/test_suite/src/json_parse_tests.cpp:100:9: warning: equality comparison result unused [-Wunused-comparison]
val == json(1.999);
~~~~^~~~~~~~~~~~~~
/home/max/big/src/jsoncons-git/jsoncons/test_suite/src/json_parse_tests.cpp:100:9: note: use '=' to turn this equality comparison into an assignment
val == json(1.999);
^~
=
/home/max/big/src/jsoncons-git/jsoncons/test_suite/src/json_parse_tests.cpp:102:9: warning: equality comparison result unused [-Wunused-comparison]
val == json(""string"");
~~~~^~~~~~~~~~~~~~~~~~~~~
/home/max/big/src/jsoncons-git/jsoncons/test_suite/src/json_parse_tests.cpp:102:9: note: use '=' to turn this equality comparison into an assignment
val == json(""string"");
^~
=
6 warnings generated.
--- end output ---

Tests do not compile with gcc 4.8.2

I tried compiling the tests for 0.95 with GCC 4.8.2 (on Ubuntu 14.04), but it didn't work.

One issue is the "typename" keyword in csv_serializer.hpp at line 62 - removing it fixes that.

The other issue is probably harder to deal with - a missing noexcept specifier in json_reader.hpp at line 51 (when implementing std::error_category). The issue is that Visual Studio versions before 2015 do no support noexcept (and neither does GCC before 4.6, I believe). So you'd need some sort of macro (like BOOST_NOEXCEPT).

I also needed to add "system" as a component to find_package(Boost) in the CMake file (it wanted it to link against the error categories - I'm not sure if there's a way to use the stdlib ones).

a little warning: extra ";"

Compiling a little test program with g++ (but clang++ say nothing), I obtain the following warning

./jsoncons/json_error_category.hpp:39:2: warning: extra ‘;’ [-Wpedantic]
};
^

And is right: a namespace isn't a class or a struct and don't want a closing ';'

Need some help reading data

Hi im using your parser to read a file, but the problem for me is that the data I want to find is within the field extrincisics, namely "rotation" and "center". The json-file looks like this:
{
"sfm_data_version": "0.2",
"root_path": "D:\Lagring\Plugg\Examensarbete\Data\images",
"views": [],
"intrinsics": [],
"extrinsics": [
{
"key": 0,
"value": {
"rotation": [
[
0.89280214808572156,
0.35067276062587932,
-0.28272413998197254
],
[
-0.090429686592667424,
0.75440463553446824,
0.65015084224113584
],
[
0.44127859245183554,
-0.5548894131618759,
0.70524530697098287
]
],
"center": [
-0.60959634064871249,
0.24123645392011658,
0.57783384588917808
]
}
},
{
"key": 1,
"value": {
"rotation": [
... etc

I successfully extract the "extrinsics" field (but not sure how to use it):
string extrinsics(jsonFile["extrinsics"].asstd::string());

And then I have tried using stringstream:
string extrinsics(jsonFile["extrinsics"].asstd::string());
stringstream ss(extrinsics);

But this just means other problems, I rather would like your parser to find the data within the field "rotation" and "center". Should be relatively simple.. what am I missing?

Extra Qualification Error

Hi Daniel,

EDIT: I rolled back to commit 7ce1d0 and it's working fine. So it could be an issue with one of your newer commits.

I have the jsoncons directory installed to my /usr/include folder. I'm getting errors when trying to compile using g++ version 4.9.3 with flag -std=c++14. The errors are below:

/usr/include/jsoncons/json1.hpp:1696:14: error: extra qualification ‘jsoncons::basic_json<Char, Alloc>::’ on member ‘basic_json’ [-fpermissive]
explicit basic_json<Char, Alloc>::basic_json()
^
/usr/include/jsoncons/json1.hpp:1696:50: error: explicit specialization of ‘jsoncons::basic_json<Char, Alloc>::basic_json()’ must be introduced by ‘template <>’
explicit basic_json<Char, Alloc>::basic_json()

For reference, here is the program that will not compile:
test.cpp:

#include <iostream>
#include <jsoncons/json.hpp>

int main(void)
{
return 0;
}

can't iterate through object by index

Running the test gives unexpected results when iterating fields of the object:

~# ./a.out
7201304
10
3

~# ./a.out
18809368
10
3


Test's source code:

int main()
{
string input = "{"first_name":"Jane", "last_name":"Roe","events":10}";
json val = json::parse_string(input);

for (int i = 0; i < val.size(); i++) {
    std::cout << val[i].type() << std::endl;
}

}

json.hpp include consistency

json.hpp includes all its headers with the prefix jsoncons, except for "json_structures.hpp", while they are all in the same folder.

jsoncons::json copy contructor causes compilation error

Hi,

Not sure if this is an issue in my code or not, but I can't copy-construct json object:

class A
{
    jsoncons::json config_;
    A(const jsoncons::json& _config):
        config_(_config)
    {
    }
};

The code was compiling just fine until I've pulled latest version of jsoncons.

/home/arychkov/git/jsoncons/src/jsoncons/json1.hpp: In instantiation of ‘static jsoncons::basic_json<Char, Alloc>::variant::string_data* jsoncons::basic_json<Char, Alloc>::variant::string_dataA::make_string_data(const Char*, size_t) [with Char = char; Alloc = std::allocator<void>; size_t = long unsigned int]’:
/home/arychkov/git/jsoncons/src/jsoncons/json1.hpp:287:70:   required from ‘jsoncons::basic_json<Char, Alloc>::variant::variant(const jsoncons::basic_json<Char, Alloc>::variant&) [with Char = char; Alloc = std::allocator<void>]’
/home/arychkov/git/jsoncons/src/jsoncons/json1.hpp:1772:24:   required from ‘jsoncons::basic_json<Char, Alloc>::basic_json(const jsoncons::basic_json<Char, Alloc>&) [with Char = char; Alloc = std::allocator<void>]’
/home/arychkov/git/tracy/include/tracy/write_to_file.hpp:58:49:   required from here
/home/arychkov/git/jsoncons/src/jsoncons/json1.hpp:210:4: error: ‘jsoncons::basic_json<Char, Alloc>::variant::string_data::string_data() [with Char = char; Alloc = std::allocator<void>]’ is private
    string_data()
    ^
/home/arychkov/git/jsoncons/src/jsoncons/json1.hpp:231:59: error: within this context
                 string_data* ps = new(storage)string_data();
                                                           ^
/home/arychkov/git/jsoncons/src/jsoncons/json1.hpp:214:10: error: ‘char* jsoncons::basic_json<char, std::allocator<void> >::variant::string_data::p’ is private
    Char* p;
          ^
/home/arychkov/git/jsoncons/src/jsoncons/json1.hpp:234:23: error: within this context
                 ps->p = new(&psa->c)Char[length_ + 1];
                       ^
/home/arychkov/git/jsoncons/src/jsoncons/json1.hpp:214:10: error: ‘char* jsoncons::basic_json<char, std::allocator<void> >::variant::string_data::p’ is private
    Char* p;
          ^
/home/arychkov/git/jsoncons/src/jsoncons/json1.hpp:235:23: error: within this context
                 memcpy(ps->p, s, length_*sizeof(Char));
                       ^
/home/arychkov/git/jsoncons/src/jsoncons/json1.hpp:214:10: error: ‘char* jsoncons::basic_json<char, std::allocator<void> >::variant::string_data::p’ is private
    Char* p;
          ^
/home/arychkov/git/jsoncons/src/jsoncons/json1.hpp:236:22: error: within this context
                 ps->p[length_] = 0;
                      ^
/home/arychkov/git/jsoncons/src/jsoncons/json1.hpp:215:11: error: ‘size_t jsoncons::basic_json<char, std::allocator<void> >::variant::string_data::length_’ is private
    size_t length_;
           ^
/home/arychkov/git/jsoncons/src/jsoncons/json1.hpp:237:29: error: within this context
                 ps->length_ = length_;

Thanks,
Alexey

problem with 64bit compiler

Trying to compile the test suite, I obtain another error that (I suppose) derives from the fact that I'm using a 64bit compiler.
My compiler says that jsoncons::csv::basic_csv_serializer<CharT>::do_integer_value(long long int) and void jsoncons::csv::basic_csv_serializer<CharT>::do_uinteger_value(long long unsigned int) are "marked override, but does not override".
This is because in the base class (jsoncons::basic_json_output_handler<Char>, if I'm not wrong) this member receiving int64_t (the first) and uint64_t.
In a 32 environment, int64_t and uint64_t are (usually) defined as long long and unsigned long long (respectively) and all goes well.
But in my 64bit environment, int64_t and uint64_t are defined as long and unsigned long (respectively), so the ovverride don't work because int64_t is different from long long and uint_64 is different from unsigned long long.
It seems obvious to me that you must uniform everything to long long and unsigned long long or to int64_t and uint64_t.
Taking into account that long long must be at least 64 bit, but can also be larger, that do_integer_value() is called with long long (json_output_handler.hpp, line 126) and than do_integer_value() isn't made (if I'm not wrong) for an argument that is exactly 64bit, I suppose that the rigth solution is change int64_t with long long. Similarly, uint64_t should be changed to unsigned long long. For do_integer_value(), do_uinteger_value(), print_integer() and print_uinteger().

I propose the following patches.

patch-7h.txt
patch-7g.txt
patch-7e.txt
patch-7d.txt
patch-7c.txt
patch-7b.txt
patch-7a.txt

I transcribe, below, the output

--- begin output ---
[ 3%] Building CXX object CMakeFiles/jsoncons_tests.dir/home/max/big/src/jsoncons-git/jsoncons/test_suite/src/csv_tests.cpp.o
In file included from /home/max/big/src/jsoncons-git/jsoncons/test_suite/src/csv_tests.cpp:11:0:
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/csv/csv_serializer.hpp: In instantiation of ‘class jsoncons::csv::basic_csv_serializer’:
/home/max/big/src/jsoncons-git/jsoncons/test_suite/src/csv_tests.cpp:494:40: required from here
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/csv/csv_serializer.hpp:274:10: error: ‘void jsoncons::csv::basic_csv_serializer::do_integer_value(long long int) [with CharT = char]’ marked override, but does not override
void do_integer_value(long long val) override
^
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/csv/csv_serializer.hpp:289:10: error: ‘void jsoncons::csv::basic_csv_serializer::do_uinteger_value(long long unsigned int) [with CharT = char]’ marked override, but does not override
void do_uinteger_value(unsigned long long val) override
^
/home/max/big/src/jsoncons-git/jsoncons/test_suite/src/csv_tests.cpp: In member function ‘void csv_test_suite::serialize_comma_delimited_file::test_method()’:
/home/max/big/src/jsoncons-git/jsoncons/test_suite/src/csv_tests.cpp:494:20: error: cannot declare variable ‘serializer’ to be of abstract type ‘jsoncons::csv::basic_csv_serializer’
csv_serializer serializer(std::cout);
^
In file included from /home/max/big/src/jsoncons-git/jsoncons/test_suite/src/csv_tests.cpp:11:0:
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/csv/csv_serializer.hpp:76:7: note: because the following virtual functions are pure within ‘jsoncons::csv::basic_csv_serializer’:
class basic_csv_serializer : public basic_json_output_handler
^
In file included from /home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons/json.hpp:21:0,
from /home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/csv/csv_reader.hpp:21,
from /home/max/big/src/jsoncons-git/jsoncons/test_suite/src/csv_tests.cpp:10:
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons/json_output_handler.hpp:181:18: note: void jsoncons::basic_json_output_handler::do_integer_value(int64_t) [with CharT = char; int64_t = long int]
virtual void do_integer_value(int64_t value) = 0;
^
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons/json_output_handler.hpp:183:18: note: void jsoncons::basic_json_output_handler::do_uinteger_value(uint64_t) [with CharT = char; uint64_t = long unsigned int]
virtual void do_uinteger_value(uint64_t value) = 0;
^
/home/max/big/src/jsoncons-git/jsoncons/test_suite/src/csv_tests.cpp: In member function ‘void csv_test_suite::serialize_tab_delimited_file::test_method()’:
/home/max/big/src/jsoncons-git/jsoncons/test_suite/src/csv_tests.cpp:529:20: error: cannot declare variable ‘serializer’ to be of abstract type ‘jsoncons::csv::basic_csv_serializer’
csv_serializer serializer(std::cout,params);
^
In file included from /home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/csv/csv_reader.hpp:17:0,
from /home/max/big/src/jsoncons-git/jsoncons/test_suite/src/csv_tests.cpp:10:
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons/json_input_handler.hpp: In instantiation of ‘class jsoncons::basic_empty_json_input_handler’:
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/csv/csv_parser.hpp:246:51: required from ‘void jsoncons::csv::basic_csv_parser::begin_parse() [with CharT = char]’
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/csv/csv_reader.hpp:113:9: required from ‘void jsoncons::csv::basic_csv_reader::read() [with CharT = char]’
/home/max/big/src/jsoncons-git/jsoncons/test_suite/src/csv_tests.cpp:34:17: required from here
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons/json_input_handler.hpp:261:10: error: ‘void jsoncons::basic_empty_json_input_handler::do_integer_value(long long int, const jsoncons::basic_parsing_context&) [with CharT = char]’ marked override, but does not override
void do_integer_value(long long, const basic_parsing_context&) override
^
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons/json_input_handler.hpp:265:10: error: ‘void jsoncons::basic_empty_json_input_handler::do_uinteger_value(long long unsigned int, const jsoncons::basic_parsing_context&) [with CharT = char]’ marked override, but does not override
void do_uinteger_value(unsigned long long, const basic_parsing_context&) override
^
In file included from /home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/csv/csv_reader.hpp:20:0,
from /home/max/big/src/jsoncons-git/jsoncons/test_suite/src/csv_tests.cpp:10:
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/csv/csv_parser.hpp: In instantiation of ‘void jsoncons::csv::basic_csv_parser::begin_parse() [with CharT = char]’:
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/csv/csv_reader.hpp:113:9: required from ‘void jsoncons::csv::basic_csv_reader::read() [with CharT = char]’
/home/max/big/src/jsoncons-git/jsoncons/test_suite/src/csv_tests.cpp:34:17: required from here
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/csv/csv_parser.hpp:246:51: error: cannot declare variable ‘ih’ to be of abstract type ‘jsoncons::basic_empty_json_input_handler’
basic_empty_json_input_handler ih;
^
In file included from /home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/csv/csv_reader.hpp:17:0,
from /home/max/big/src/jsoncons-git/jsoncons/test_suite/src/csv_tests.cpp:10:
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons/json_input_handler.hpp:208:7: note: because the following virtual functions are pure within ‘jsoncons::basic_empty_json_input_handler’:
class basic_empty_json_input_handler : public basic_json_input_handler
^
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons/json_input_handler.hpp:199:18: note: void jsoncons::basic_json_input_handler::do_integer_value(int64_t, const jsoncons::basic_parsing_context&) [with CharT = char; int64_t = long int]
virtual void do_integer_value(int64_t value, const basic_parsing_context& context) = 0;
^
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons/json_input_handler.hpp:201:18: note: void jsoncons::basic_json_input_handler::do_uinteger_value(uint64_t, const jsoncons::basic_parsing_context&) [with CharT = char; uint64_t = long unsigned int]
virtual void do_uinteger_value(uint64_t value, const basic_parsing_context& context) = 0;
^
In file included from /home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/csv/csv_reader.hpp:20:0,
from /home/max/big/src/jsoncons-git/jsoncons/test_suite/src/csv_tests.cpp:10:
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/csv/csv_parser.hpp:260:51: error: cannot declare variable ‘ih’ to be of abstract type ‘jsoncons::basic_empty_json_input_handler’
basic_empty_json_input_handler ih;
^
CMakeFiles/jsoncons_tests.dir/build.make:675: set di istruzioni per l'obiettivo "CMakeFiles/jsoncons_tests.dir/home/max/big/src/jsoncons-git/jsoncons/test_suite/src/csv_tests.cpp.o" non riuscito
make[2]: *** [CMakeFiles/jsoncons_tests.dir/home/max/big/src/jsoncons-git/jsoncons/test_suite/src/csv_tests.cpp.o] Errore 1
CMakeFiles/Makefile2:60: set di istruzioni per l'obiettivo "CMakeFiles/jsoncons_tests.dir/all" non riuscito
make[1]: *** [CMakeFiles/jsoncons_tests.dir/all] Errore 2
Makefile:76: set di istruzioni per l'obiettivo "all" non riuscito
make: *** [all] Errore 2
--- end output ---

error: no matching function for call to ‘json_query...

Next error: there is a problem compiling jsoncons_ext/jsonpath/json_query.hpp.
At line 87

return json_query(root,path,std::char_traits<typename JsonT::char_type>::length(path));

my compiler give me the error

"error: no matching function for call to ‘json_query(const jsoncons::basic_jsonstd::basic_string<char, std::allocator >&, const char_type*&, std::size_t)"

I suppose that the problem is that in json_query.hpp are three overloaded versions of json_query() that are defined in the wrong order: the first and the second version (2 arguments) are calling the third version (3 arguments); but the third version should be defined first to be visible to the others versions.

I attach a possible patch

patch-5.txt

I transcribe, below, the output

--- begin output ---
[ 3%] Building CXX object CMakeFiles/jsoncons_tests.dir/home/max/big/src/jsoncons-git/jsoncons/test_suite/src/jsonpath_filter_tests.cpp.o
In file included from /home/max/big/src/jsoncons-git/jsoncons/test_suite/src/jsonpath_filter_tests.cpp:15:0:
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/json_query.hpp: In instantiation of ‘JsonT jsoncons::jsonpath::json_query(const JsonT&, const typename JsonT::char_type_) [with JsonT = jsoncons::basic_jsonstd::basic_string<char, std::allocator >; typename JsonT::char_type = char]’:
/home/max/big/src/jsoncons-git/jsoncons/test_suite/src/jsonpath_filter_tests.cpp:102:58: required from here
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/json_query.hpp:87:90: error: no matching function for call to ‘json_query(const jsoncons::basic_jsonstd::basic_string<char, std::allocator >&, const char_type_&, std::size_t)’
return json_query(root,path,std::char_traits::length(path));
^
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/json_query.hpp:87:90: note: candidates are:
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/json_query.hpp:79:7: note: template JsonT jsoncons::jsonpath::json_query(const JsonT&, const typename JsonT::string_type&)
JsonT json_query(const JsonT& root, const typename JsonT::string_type& path)
^
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/json_query.hpp:79:7: note: template argument deduction/substitution failed:
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/json_query.hpp:87:90: note: candidate expects 2 arguments, 3 provided
return json_query(root,path,std::char_traits::length(path));
^
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/json_query.hpp:85:7: note: template JsonT jsoncons::jsonpath::json_query(const JsonT&, const typename JsonT::char_type_)
JsonT json_query(const JsonT& root, const typename JsonT::char_type_ path)
^
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/json_query.hpp:85:7: note: template argument deduction/substitution failed:
/home/max/big/src/jsoncons-git/jsoncons/test_suite/build/cmake/../../../src/jsoncons_ext/jsonpath/json_query.hpp:87:90: note: candidate expects 2 arguments, 3 provided
return json_query(root,path,std::char_traits::length(path));
^
CMakeFiles/jsoncons_tests.dir/build.make:238: set di istruzioni per l'obiettivo "CMakeFiles/jsoncons_tests.dir/home/max/big/src/jsoncons-git/jsoncons/test_suite/src/jsonpath_filter_tests.cpp.o" non riuscito
make[2]: *** [CMakeFiles/jsoncons_tests.dir/home/max/big/src/jsoncons-git/jsoncons/test_suite/src/jsonpath_filter_tests.cpp.o] Errore 1
CMakeFiles/Makefile2:60: set di istruzioni per l'obiettivo "CMakeFiles/jsoncons_tests.dir/all" non riuscito
make[1]: *** [CMakeFiles/jsoncons_tests.dir/all] Errore 2
Makefile:76: set di istruzioni per l'obiettivo "all" non riuscito
make: *** [all] Errore 2
--- end output ---

Compilation error

diff --git a/src/jsoncons/json1.hpp b/src/jsoncons/json1.hpp
index e1ba2b0..0f59aea 100644
--- a/src/jsoncons/json1.hpp
+++ b/src/jsoncons/json1.hpp
@@ -255,13 +255,13 @@ public:
         }

         variant(const json_object<Char,Alloc>& val)
-            : type_(value_types::object)
+            : type_(value_types::object_t)
         {
             value_.object_ = val.clone();
         }

         variant(const json_array<Char,Alloc>& val)
-            : type_(value_types::array)
+            : type_(value_types::array_t)
         {
             value_.array_ = val.clone();
         }

Kind regards,
Alexey

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.