Newtonsoft.json: Add buffered reading of binary data to JsonTextReader

Created on 10 Oct 2017  路  2Comments  路  Source: JamesNK/Newtonsoft.Json

I have a JSON containing a binary property with a very large value:
{ "NormalStringValue" : "test", "NormalIntValue" : 1, "LargeBinaryValueInBase64": "AQB...." }
The standard JsonTextReader.ReadAsBytes reads the value of a LargeBinaryProperty at once so a large byte array is allocated. I want to avoid this. For XmlTextReader there is a ReadContentAsBase64(byte[] buffer, int offset, int count) method which can perform buffered reading of a BASE64 content.
Is it possible to implement such a functionality for JsonTextReader?

Most helpful comment

I have the same need. I don't know what developers who create such APIs (which return blobs in JSON) have in their minds, but I have to work with that, so streamed property value reading is a must have. However, I would advocate for a Stream-typed read result instead of reading in chunks into a buffer.

All 2 comments

Hello!

Maybe someone could give a hint on how to implement it myself?
I don't see any extension points in JsonTextReader which are suitable for this.

I have the same need. I don't know what developers who create such APIs (which return blobs in JSON) have in their minds, but I have to work with that, so streamed property value reading is a must have. However, I would advocate for a Stream-typed read result instead of reading in chunks into a buffer.

Was this page helpful?
0 / 5 - 0 ratings