Open
Conversation
This change allows users to insert pre-encoded JSON `iodata()` anywhere there can be a valid `json_value()` (i.e., anywhere except object keys). This approach occurred to me looking at PR davisp#139 from @dhull. The technical difference being that this approach does not copy the given `iodata()` into the output and instead re-uses the same input term as part of the output `iodata()`.
6801624 to
02ee896
Compare
02ee896 to
d3ce6e7
Compare
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.
This pull request is a rewrite of #139 that uses @davisp's approach to including pre-encoded JSON in the input.
It adds a new function
jiffy:partial_encode/2that takes an array or object and returns a term that can later be included as part of the input in a futurejiffy:encodecall.It uses the atoms
$partial_array$and$partial_object$to mark these partially-encoded values. For the partially-encoded array we could technically usejsonbut I added$partial_array$because the partially-encoded array is not well-formed JSON while the JSON in{json, Json}is, and I thought it was worth distinguishing the two.I did not test my code with native Erlang maps but I believe it will work if the tuple
{Key, Value}returned byjiffy_partial_encodeis added to the map bymap:put(Key, Value, Map).