josephburnett / jd

JSON diff and patch
MIT License
826 stars 38 forks source link

Read bytes #56

Closed morphy2k closed 1 month ago

morphy2k commented 1 year ago

Adds functions to accept JSON and YAML in bytes to avoid unnecessary conversion in some cases.

The motivation behind this is a tool I wrote in which I have JSON as bytes.

josephburnett commented 1 year ago

Thanks for the pull request! I'd like to know a little more about your use case. Are you serializing to JSON right before passing to JD? I think the conversion between bytes and string doesn't actually cost anything in terms of cpu time or memory space. However if you're regularly diffing object, you might have to serialize to JSON, check for errors, then pass to JD. I could see a ReadJSONBytes function that also check the error for you, so could do something like: jd.ReadJSONBytes(json.Marshal(object)). But in that case, we might prefer something that will do that Marshal for you.

Anyway, tell me a little more about your needs or maybe a few code examples. Thanks!