Skip to content

Conversation

@kfwu1999
Copy link
Contributor

@kfwu1999 kfwu1999 commented Sep 25, 2024

Description

In #4453, the compilation error of json::json_pointer p = "/nested/one"; is due to the implicit conversion, as the constructor for json_pointer is marked explicit (see following source code).

explicit json_pointer(const string_t& s = "")
: reference_tokens(split(s))
{}

Removing the explicit can allows to compile and pass the test, but i think it it might violate the design intentions.

Modification

Changed the example code in the documentation (https://json.nlohmann.me/features/json_pointer/#json-pointer-creation) from copy initialization to direct initialization.

Before

json::json_pointer p = "/nested/one";

After

json::json_pointer p("/nested/one");

Pull request checklist

Read the Contribution Guidelines for detailed information.

  • Changes are described in the pull request, or an existing issue is referenced.
  • The test suite compiles and runs without error.
  • Code coverage is 100%. Test cases can be added by editing the test suite.
  • The source code is amalgamated; that is, after making changes to the sources in the include/nlohmann directory, run make amalgamate to create the single-header files single_include/nlohmann/json.hpp and single_include/nlohmann/json_fwd.hpp. The whole process is described here.

Changed the example code in the documentation from copy initialization
to direct initialization for `json::json_pointer`.
This prevents compilation errors caused by the constructor being explicit.
@github-actions
Copy link

This pull request has been marked as stale because it has had no activity for 30 days. While we won’t close it automatically, we encourage you to update or comment if it is still relevant. Keeping pull requests active and up-to-date helps us review and merge changes more efficiently. Thank you for your contributions!

@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 Jan 19, 2025
@nlohmann nlohmann linked an issue May 22, 2025 that may be closed by this pull request
2 tasks
@nlohmann nlohmann removed the state: stale the issue has not been updated in a while and will be closed automatically soon unless it is updated label May 22, 2025
Copy link
Owner

@nlohmann nlohmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

@nlohmann nlohmann added this to the Release 3.12.1 milestone May 22, 2025
@nlohmann nlohmann merged commit 7421ac3 into nlohmann:develop May 22, 2025
3 checks passed
nlohmann pushed a commit that referenced this pull request May 25, 2025
Changed the example code in the documentation from copy initialization
to direct initialization for `json::json_pointer`.
This prevents compilation errors caused by the constructor being explicit.
nlohmann pushed a commit that referenced this pull request May 25, 2025
Changed the example code in the documentation from copy initialization
to direct initialization for `json::json_pointer`.
This prevents compilation errors caused by the constructor being explicit.

Signed-off-by: Niels Lohmann <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

json_pointer - a code example from doc's does not compile

2 participants