nlohmann / json

JSON for Modern C++
https://json.nlohmann.me
MIT License
41.46k stars 6.59k forks source link

warning on at(nlohmann::json_pointer) #4103

Open manifolds opened 11 months ago

manifolds commented 11 months ago

Description

warning on at(nlohmann::json_pointer)

_warning: ‘nlohmann::json_abi_v3_11_2::json_pointer::operator nlohmann::json_abi_v3_11_2::json_pointer::string_t() const [with RefStringType = std::basic_string; nlohmann::json_abi_v3_11_2::json_pointer::string_t = std::basic_string]’ is deprecated (declared at /home/tty2099/Workspace/AutoTradingSystem/third_party/nlohmann_json/include/nlohmann/detail/json_pointer.hpp:81): Since 3.11.0; use tostring() [-Wdeprecated-declarations]

It's warning when compiling the code, but It can find the node correctly. When I call with at(nlohmann::json_pointer::to_string()), it cannot find the json node.

I cannot understand the purpose of the find function with json_pointer parameter, it will not find the node when I call it with the json_pointer paramter or with the json_pointer::to_string() paramter.

Reproduction steps


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

int main(int argc, char** argv)
{
    nlohmann::json j2 = {
      {"pi", 3.141},
      {"happy", true},
      {"name", "Niels"},
      {"nothing", nullptr},
      {"answer", {
        {"everything", 42}
      }},
      {"list", {1, 0, 2}},
      {"object", {
        {"currency", "USD"},
        {"value", 42.99}
      }}
    };

    nlohmann::json_pointer<std::string> ptr;
    ptr.push_back("object");
    ptr.push_back("value");
    std::cout<<"pointer value: "<< j2.at(ptr).get<double>()<<std::endl;
    std::cout<<"pointer value: "<< j2.at(ptr.to_string()).get<double>()<<std::endl;
    auto itr = j2.find(ptr);
    if(itr!=j2.cend()) std::cout<<"find --- 0"<<std::endl;
    itr = j2.find(ptr.to_string());
    if(itr!=j2.cend()) std::cout<<"find --- 1"<<std::endl;
    return EXIT_SUCCESS;
}

Expected vs. actual results

I think at(nlohmann::json_pointer) and at(nlohmann::json_pointer::to_string()) calls return the same result, nlohmann::json should find the node according the path that nlohmann::json_pointer supplied.

I think the find function should also be work in this way.

Minimal code example

No response

Error messages

No response

Compiler and operating system

CentOS7

Library version

3.11.0

Validation