Skip to content

Conversation

@dhull
Copy link
Contributor

@dhull dhull commented Mar 16, 2017

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/2 that takes an array or object and returns a term that can later be included as part of the input in a future jiffy:encode call.

PartialArray = jiffy:partial_encode([ 1, 2 ], []).
PartialObject = jiffy:partial_encode({[ {one, 1} ]}, []).
iolist_to_binary(jiffy:encode([ [ PartialArray, 3 ], {[ PartialObject, {two, 2} ]} ])).
%% => <<"[[1,2,3],{\"one\":1,\"two\":2}]">>

It uses the atoms $partial_array$ and $partial_object$ to mark these partially-encoded values. For the partially-encoded array we could technically use json but 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 by jiffy_partial_encode is added to the map by map:put(Key, Value, Map).

Copy link

@facekoob facekoob left a comment

Choose a reason for hiding this comment

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

iPad icloud bypass

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()`.
@dhull dhull force-pushed the preencoded-json-support2 branch from 6801624 to 02ee896 Compare August 7, 2018 15:57
@dhull dhull force-pushed the preencoded-json-support2 branch from 02ee896 to d3ce6e7 Compare October 15, 2018 22:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants