docs: document how discarded values are removed by the parser callback - #5354
Open
nlohmann wants to merge 1 commit into
Open
docs: document how discarded values are removed by the parser callback#5354nlohmann wants to merge 1 commit into
nlohmann wants to merge 1 commit into
Conversation
Follow-up to #5342, which fixed the parser callback leaving a discarded member behind when an array or a value under an object key was rejected. The documentation of parser_callback_t only stated that discarded values in structured types are skipped, without saying that this covers object parents and that the key is removed along with the value, so there was no way to tell the fixed behavior from the buggy one. Spell out the discarding rules, add an example that exercises the cases the fix repaired, and correct the return value description: a discarded top-level value is replaced by null, not by "an empty discarded object". Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #5342, which left the documentation checkbox unchecked.
That PR fixed
json::parsewith a callback leaving a discarded member behind when an array — or a scalar — under an object key was rejected, so thatdump()printed things like{"IDs":<discarded>,"Width":800}. The behavior is now correct, butparser_callback_tonly said that "discarded values in structured types are skipped", which was equally compatible with the buggy behavior. Nothing documented that an object parent is covered too, that the key is removed along with the value, or that discarding an array atarray_startand atarray_endboth work.This PR:
keyevent drops the whole member while the value callback still runs.examples/parser_callback_t.cpp, which discards the same array atarray_startand atarray_end, a number with and without its key, and the top-level object. Compiled against the parent of remove discarded array from parent object in end_array #5342, three of its five output lines are invalid JSON containing<discarded>; ondevelopall five are correct — so the example is a regression demonstration, not just prose.null(parser.hpp), and no discarded value survives anywhere else.Every documented claim was verified against the current implementation by instrumenting the callback and printing the event sequence, rather than read off the source.
Breaking changes
No breaking changes. This PR touches only
docs/: one Markdown page and two new example files. No header, no test, and no build file is modified, so there is no change to the public API, the ABI, or any behavior.make amalgamate. (Not applicable — no header changes.)Checked locally:
check_structure.pyreports no warnings, andmake mkdocs/docs/examples/parser_callback_t.testpasses (generated output matches the committed.output).This pull request was written by Claude Code.