allowSpecialFloatingPointValues
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.
Example of usage:
val floats = listOf(1.0, 2.0, Double.NaN, Double.NEGATIVE_INFINITY)
val json = Json { allowSpecialFloatingPointValues = true }
// Prints [1.0,2.0,NaN,-Infinity]
println(json.encodeToString(floats))
// Prints [1.0, 2.0, NaN, -Infinity]
println(json.decodeFromString<List<Double>>("[1.0,2.0,NaN,-Infinity]"))
Content copied to clipboard