Skip to content

Commit 30b1732

Browse files
Clarify that Json.isLenient flag only affects invalid json such as unquoted strings and does not affect quoted values type mapping. (#2754)
Fixes #2749 Co-authored-by: Sergey Shanshin <[email protected]>
1 parent 1b69687 commit 30b1732

File tree

2 files changed

+7
-2
lines changed
  • docs
  • formats/json/commonMain/src/kotlinx/serialization/json

2 files changed

+7
-2
lines changed

docs/json.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,15 @@ fun main() {
122122

123123
> You can get the full code [here](../guide/example/example-json-02.kt).
124124
125-
You get the object, even though all keys of the source JSON, string, and enum values are unquoted, while an
126-
integer is quoted:
125+
You get the object, even though all keys of the source JSON, string and enum values are unquoted:
127126

128127
```text
129128
Project(name=kotlinx.serialization, status=SUPPORTED, votes=9000)
130129
```
131130

131+
> Note that parsing of quoted numbers or booleans such as `votes: "9000"` to `val votes: Int` is generally allowed by kotlinx.serialization
132+
> regardless of the `isLenient` flag, since such JSON is syntactically valid.
133+
132134
<!--- TEST -->
133135

134136
### Ignoring unknown keys

formats/json/commonMain/src/kotlinx/serialization/json/Json.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,9 @@ public class JsonBuilder internal constructor(json: Json) {
418418
* Removes JSON specification restriction (RFC-4627) and makes parser
419419
* more liberal to the malformed input. In lenient mode, unquoted JSON keys and string values are allowed.
420420
*
421+
* Example of invalid JSON that is accepted with this flag set:
422+
* `{key: value}` can be parsed into `@Serializable class Data(val key: String)`.
423+
*
421424
* Its relaxations can be expanded in the future, so that lenient parser becomes even more
422425
* permissive to invalid values in the input.
423426
*

0 commit comments

Comments
 (0)