jiffy
jiffy copied to clipboard
Add preencoded JSON support.
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).
@dhull Sorry for taking so long to get back to you on this. While looking at your change this approach occurred to me:
https://github.com/davisp/jiffy/commit/46136403945d03224f9e7fe545ebbfdf5dfae057
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">>}]).
Thanks! That (https://github.com/davisp/jiffy/commit/46136403945d03224f9e7fe545ebbfdf5dfae057) 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. :)