Poison cannot parrse a json string that has 0 prefix

89 views Asked by At

Poison return invalid when I parse a valid json string that has 0 prefix. For example,

Poison.Parser.parse("{\"mynumber\":09315}") returns {:error, {:invalid, "9", 13}}, but if I remove 0 prefix Poison.Parser.parse("{\"mynumber\":9315}") returns {:ok, %{"mynumber" => 9315}}.

I would like to know why "{\"mynumber\":09315}" is not valid. Is there any workaround?

1

There are 1 answers

0
Khaino On

Why is JSON invalid if an integer begins with a leading zero? explains the reason why "{\"mynumber\":09315}" is invalid.

for workaround I just replace wiht String.replace("{\"mynumber\":09315}", ~r/\"mynumber\"\:0*/, "\"mynumber\":") before parsing it