JsonBuilder
Builder of the Json instance provided by Json { ... }
factory function:
val json = Json { // this: JsonBuilder
encodeDefaults = true
ignoreUnknownKeys = true
}
Properties
Allows parser to accept C/Java-style comments in JSON input.
Removes JSON specification restriction on special floating-point values such as NaN
and Infinity
and enables their serialization and deserialization as float literals without quotes. When enabling it, please ensure that the receiving party will be able to encode and decode these special values. This option affects both encoding and decoding. false
by default.
Enables structured objects to be serialized as map keys by changing serialized form of the map from JSON object (key-value pairs) to flat array like [k1, v1, k2, v2]
. false
by default.
Allows parser to accept trailing (ending) commas in JSON objects and arrays, making inputs like [1, 2, 3,]
and {"key": "value",}
valid. Does not affect encoding. false
by default.
Name of the class descriptor property for polymorphic serialization. type
by default.
Defines which classes and objects should have class discriminator added to the output. ClassDiscriminatorMode.POLYMORPHIC by default.
Enables coercing incorrect JSON values in the following cases:
Enables decoding enum values in a case-insensitive manner. Encoding is not affected by this option.
Specifies whether default values of Kotlin properties should be encoded. false
by default.
Specifies whether null
values should be encoded for nullable properties and must be present in JSON object during decoding.
Specifies whether encounters of unknown properties in the input JSON should be ignored instead of throwing SerializationException. false
by default.
Specifies JsonNamingStrategy that should be used for all properties in classes for serialization and deserialization.
Specifies whether resulting JSON should be pretty-printed: formatted and optimized for human readability. false
by default.
Specifies indent string to use with prettyPrint mode. Only whitespace characters are allowed: ' ', '\n', '\r' or '\t'. 4 spaces by default.
Module with contextual and polymorphic serializers to be used in the resulting Json instance.
Specifies whether Json instance makes use of JsonNames annotation.
Switches polymorphic serialization to the default array format. This is an option for legacy JSON format and should not be generally used. false
by default.