I wrote a JSON encoder/decoder for Rebol 2. I'm rewriting it for Rebol 3 and would prefer to make it available in Rebol 3 as a codec:
load %data.json
save %data.json object
decode 'json to-binary {["some","json"]}
How should I go about this?
At the time of asking, documentation on this subject is scarce.
The simple answer is that you can't. As for why, there are several answers to that.
- The current codec model is undocumented. Only Carl knows how to write codecs at the moment. Though someone might be able to look at the source and figure it out, noone has yet.
- The current codec functions aren't really flexible enough to make what you want here. You could make a decoder, but not an encoder because
encode
only takes images, binaries or strings. Maybe just having a decoder is enough for you though.
- Only native codecs are supported by the current model. You can't write codecs in Rebol code, and for a parser that means that you can't use
parse
. Do you have a native code version of your parser?
- The current codec model is a placeholder for the codec model we hope to eventually have. This is why it hasn't been that well documented. We eventually hope to support incremental en/decoding, codecs that can read directly from files or other ports, and Rebol codecs. However, we haven't really decided on the final model yet, or even started the discussion of how it will be designed, beyond initial criticisms.
I wish there was a better answer to your question right now.