Other ways of streaming JSON
There are other ways of streaming JSON:
- Concatenated JSON simply writes JSON objects one after the other
- Newline-delimited JSON writes every JSON object as a separate line
- Record separator-delimited JSON uses a special record separator character, 0x1E, and optionally a newline between each JSON object
- Length-prefixed JSON prefixes the string length of every JSON object as a decimal number
All these can be read and written using json.Decoder
and json.Encoder
. A simple package for JSON streaming can be found here: https://github.com/bserdar/jsonstream.
Security considerations
Whenever you accept data from outside your application (user-entered data, API calls, reading a file, etc.), you have to be concerned about malicious input. JSON input is relatively safe because JSON parsers do not perform data expansions like YAML or XML parsers do. Nevertheless, there are still things you need to consider when dealing with JSON data...