avro-0.6.1.2: Avro serialization support for Haskell
Safe HaskellSafe-Inferred
LanguageHaskell2010

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 TypeJSON TypeExample
nullnullnull
booleanbooleantrue
int, longinteger1
float, doublenumber1.1
bytesstring"u00FF"
stringstring"foo"
recordobject{"a":1}
enumstringFOO
arrayarray[1]
mapobject{"a":1}
fixedstring"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 : { ... } }

Documentation