ignoreUnknownKeys

Specifies whether encounters of unknown properties in the input JSON should be ignored instead of throwing SerializationException. false by default.

Example of usage:

@Serializable
data class Project(val name: String)
val withUnknownKeys = Json { ignoreUnknownKeys = true }
// Project(name=unknown), "version" is ignored completely
println(withUnknownKeys.decodeFromString<Project>("""{"name":"unknown", "version": 2.0}"""))
// Fails with "Encountered an unknown key 'version'"
Json.decodeFromString<Project>("""{"name":"unknown", "version": 2.0}""")

In case you wish to allow unknown properties only for specific class(es), consider using JsonIgnoreUnknownKeys annotation instead of this configuration flag.

See also