Skip to content

Commit

Permalink
Clarify that Json.isLenient flag only affects invalid json such as un…
Browse files Browse the repository at this point in the history
…quoted strings and does not affect quoted values type mapping. (#2754)

Fixes #2749

Co-authored-by: Sergey Shanshin <sergey.shanshin@jetbrains.com>
  • Loading branch information
sandwwraith and shanshin authored Aug 5, 2024
1 parent 1b69687 commit 30b1732
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
6 changes: 4 additions & 2 deletions docs/json.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,15 @@ fun main() {

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

```text
Project(name=kotlinx.serialization, status=SUPPORTED, votes=9000)
```

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

### Ignoring unknown keys
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,9 @@ public class JsonBuilder internal constructor(json: Json) {
* Removes JSON specification restriction (RFC-4627) and makes parser
* more liberal to the malformed input. In lenient mode, unquoted JSON keys and string values are allowed.
*
* Example of invalid JSON that is accepted with this flag set:
* `{key: value}` can be parsed into `@Serializable class Data(val key: String)`.
*
* Its relaxations can be expanded in the future, so that lenient parser becomes even more
* permissive to invalid values in the input.
*
Expand Down

0 comments on commit 30b1732

Please sign in to comment.