You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For some of the code I am using nlohmann for I need a way to retrieve the raw/original text of a nested object within the json object I am parsing. This can be useful, for example, in cases where one may have a json that includes a nested object and its hash, where having a way to retrieve the raw text of that nested object would prevent having to set a strict format for the text that needs to be hashed (considering setting such strictness on the formatting can make things less usable).
I would like to be able to retrieve the exact text of "details" as it is (considering whitespaces, order, line breaks, etc.), so I can verify its hash matches "data_hash".
How this could be done
I have looked at the code and couldn't find a way to do this.
I believe it would be possible to add a new parser callback or extend the signature of the parser callback to include information about the character position in the original text for where an object starts/ends based on the type of parsing event (e.g., at object_start and object_end).
The SAX interface also seems like a possible candidate to be extended to provide this information while parsing an object.
For the internal implementation, I believe this could use information already held by the lexer to return the location in the original text of the elements being parsed.
I wanted to know if this is something that is possible and I am missing something, or whether it would be a contribution I could work on making to the project. And for the latter, whether the above suggestions seem like reasonable approaches to making this change.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Description
For some of the code I am using nlohmann for I need a way to retrieve the raw/original text of a nested object within the json object I am parsing. This can be useful, for example, in cases where one may have a json that includes a nested object and its hash, where having a way to retrieve the raw text of that nested object would prevent having to set a strict format for the text that needs to be hashed (considering setting such strictness on the formatting can make things less usable).
Example
Given the following json:
I would like to be able to retrieve the exact text of "details" as it is (considering whitespaces, order, line breaks, etc.), so I can verify its hash matches "data_hash".
How this could be done
I have looked at the code and couldn't find a way to do this.
I believe it would be possible to add a new parser callback or extend the signature of the parser callback to include information about the character position in the original text for where an object starts/ends based on the type of parsing event (e.g., at object_start and object_end).
The SAX interface also seems like a possible candidate to be extended to provide this information while parsing an object.
For the internal implementation, I believe this could use information already held by the lexer to return the location in the original text of the elements being parsed.
I wanted to know if this is something that is possible and I am missing something, or whether it would be a contribution I could work on making to the project. And for the latter, whether the above suggestions seem like reasonable approaches to making this change.
Beta Was this translation helpful? Give feedback.
All reactions