Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serde failing to parse string with additional whitespace #37

Open
maxRN opened this issue Sep 30, 2024 · 2 comments · May be fixed by #38
Open

Serde failing to parse string with additional whitespace #37

maxRN opened this issue Sep 30, 2024 · 2 comments · May be fixed by #38

Comments

@maxRN
Copy link
Contributor

maxRN commented Sep 30, 2024

Serde fails to parse this JSON object correctly:

{ "x": [ { "name": "max" } ] }

with the following type definitions:

type a = { name : string } [@@deriving deserialize, serialize,]
type t = { x : a list } [@@deriving deserialize, serialize,]

error message:

Fatal error: exception Yojson__Common.Json_error("Line 6, bytes 5-12:\nExpected ',' but found '\n  ]\n}\n'")

I have created a reproduction repo here: https://github.com/maxrn/serde_list_repro

Copy link

linear bot commented Sep 30, 2024

@maxRN
Copy link
Contributor Author

maxRN commented Oct 2, 2024

Did some more investigating and it seems to be related to white space. Here are two examples that don't work

let does_not_work = {| { "records": [ { "hello": "some str" } ] } |};;
(*                                                           ^ the problem *)
let does_not_work2 = {| { "records": [ { "hello": "some str" } , { "hello": "some other str" }] } |};;
(*                                                            ^ the problematic whitespace *)

whereas these two strings parse fine:

let this_works = {| { "records": [ { "hello": "some str" }] } |};;
let this_works2 = {| { "records": [ { "hello": "some str" }, { "hello": "some other str" }] } |};;

Note the additional whitespace between } ] and } , in the non-working examples.

@maxRN maxRN linked a pull request Oct 2, 2024 that will close this issue
@maxRN maxRN changed the title Serde failing to parse list with one object Serde failing to parse string with additional whitespace Oct 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant