Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

warning on at(nlohmann::json_pointer) #4103

Open
1 of 2 tasks
manifolds opened this issue Aug 9, 2023 · 1 comment
Open
1 of 2 tasks

warning on at(nlohmann::json_pointer) #4103

manifolds opened this issue Aug 9, 2023 · 1 comment
Labels
kind: bug state: stale the issue has not been updated in a while and will be closed automatically soon unless it is updated

Comments

@manifolds
Copy link

manifolds commented Aug 9, 2023

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 to_string() [-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_pointerstd::string) and at(nlohmann::json_pointerstd::string::to_string()) calls return the same result, nlohmann::json should find the node according the path that nlohmann::json_pointerstd::string 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

Copy link

github-actions bot commented Feb 4, 2025

This issue has been marked as stale because it has been open for 90 days without activity. If this issue is still relevant, please add a comment or remove the "stale" label. Otherwise, it will be closed in 10 days. Thank you for helping us prioritize our work!

@github-actions github-actions bot added the state: stale the issue has not been updated in a while and will be closed automatically soon unless it is updated label Feb 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: bug state: stale the issue has not been updated in a while and will be closed automatically soon unless it is updated
Projects
None yet
Development

No branches or pull requests

1 participant