avro-0.5.2.0: Avro serialization support for Haskell

Data.Avro.JSON

Description

Avro supports a JSON representation of Avro objects alongside the Avro binary format. An Avro schema can be used to generate and validate JSON representations of Avro objects.

The JSON format is the same format as used for default values in schemas except unions are encoded differently. Non-union values are encoded as follows:

Avro Type JSON Type Example
null null null
boolean boolean true
int, long integer 1
float, double number 1.1
bytes string "u00FF"
string string "foo"
record object {"a":1}
enum string FOO
array array [1]
map object {"a":1}
fixed string "u00FF"

(Table from the Avro 1.8.2 specification: https://avro.apache.org/docs/1.8.2/spec.html#schema_record)

Bytes and fixed are encoded as JSON strings where each byte is translated into the corresponding Unicode codepoint between 0–255, which includes non-printable characters. Note that this encoding happens at the Unicode code-point level, meaning it is independent of text encoding. (JSON is, by definition, encoded in UTF8.)

Unions are encoded as an object with a single field that specifies the "branch" of the union. If the branch is a primitive type like "string", the name of the primitive type is used:

{ "string" : "foo" }


For named types (record, enum and fixed), the name of the type is used:

{ MyRecord : { ... } }