· Nov 7, 2016

Binary Support in JSON?

I'm working on a REST service which will include a binary stream as a request property. I'm currently encoding the stream as BASE64 and passing it as a string value, but I was wondering if there is anything in the Caché JSON support that may be a better fit for encoding this data? Thanks Chris

Discussion (3)0
Log in or sign up to continue

A follow up question.  I was able to push across a small filestream using my REST services, with the file stream encoded in BASE 64.  I then tried a large file, and received a MAXSTRING error.  I clearly need to use Streams to get round this, and was looking at the class documentation.  I believe there aren't Stream capable versions of the following functions, but I thought I'd ask here before I started coding:

1. Base64Encode (and Decode)

2. toJSON() (and fromJSON)

You are correct in your assumption, you have to work with streams to operate on arbitrarely large JSON. %ToJSON and %FromJSON work with streams. Here is an example how streams can work with %FromJSON to read a file:

        set fileStream = ##class(%Stream.FileCharacter).%New()
        set jsonObject = ##class(%DynamicObject).%FromJSON(fileStream)