Skip to content

Conversation

@dhull
Copy link
Contributor

@dhull dhull commented Mar 14, 2017

Issue #128 requested support for preencoded raw JSON in jiffy:encode. Since this is something that would be useful for me too I wrote some code to implement it. Is this something that you are interested in supporting in mainline jiffy? If so, let me know and I will continue with adding documentation to get this pull request to a mergeable state. As it is, I have used the syntax suggested in #128, namely {json, JSON} is accepted anywhere a json_value() is.

I'm also considering adding support for partially-encoded objects and lists (where more fields could later be added to the object or more elements to the list).

davisp added a commit that referenced this pull request Mar 15, 2017
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 #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()`.
@davisp
Copy link
Owner

davisp commented Mar 15, 2017

@dhull Sorry for taking so long to get back to you on this. While looking at your change this approach occurred to me:

4613640

Theoretically it'd be faster as well since its avoiding the copies to the internal Jiffy buffers (though that likely wholly depends on the size of the pre-encoded data being inserted (though if its tiny then you likely shouldn't be using this approach because its bypassing a bunch of safety checks)).

Theoretically adding the ability to have pre-encoded keys and arbitrary key/value pairs could be added but I'd have to think harder on it. Adding arbitrary elements to an array should already just work with jiffy:encode([{json, <<"1,2">>}]).

@dhull
Copy link
Contributor Author

dhull commented Mar 16, 2017

Thanks! That (4613640) is an impressively minimal solution. I had already coded a partial_encode function for arrays and objects when I saw this. I'll push those commits to this pull request in case you're interested in looking at the code. I'll also adapt my code to use your technique and open a separate pull request.

Adding arbitrary elements to an array should already just work with jiffy:encode([{json, <<"1,2">>}]).

Yes, I discovered that after I wrote some special-purpose code to handle it. :)

@dhull dhull force-pushed the preencoded-json-support branch from a132437 to 704547f Compare March 16, 2017 16:41
dhull pushed a commit to dhull/jiffy that referenced this pull request Aug 7, 2018
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()`.
Kuroneer pushed a commit to Kuroneer/jiffy that referenced this pull request Mar 23, 2020
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()`.
Kuroneer pushed a commit to Kuroneer/jiffy that referenced this pull request Mar 24, 2020
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()`.
Kuroneer pushed a commit to Kuroneer/jiffy that referenced this pull request Mar 24, 2020
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()`.
Kuroneer pushed a commit to Kuroneer/jiffy that referenced this pull request Mar 24, 2020
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()`.
Kuroneer pushed a commit to Kuroneer/jiffy that referenced this pull request Mar 24, 2020
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()`.
Kuroneer pushed a commit to Kuroneer/jiffy that referenced this pull request Mar 24, 2020
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()`.
Kuroneer pushed a commit to Kuroneer/jiffy that referenced this pull request Mar 24, 2020
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()`.
kenan-gillet pushed a commit to openx/jiffy that referenced this pull request Apr 20, 2022
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()`.
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.

2 participants