NaN values in JSON

1,224 views
Skip to first unread message

jack rudnick

unread,
Jun 17, 2014, 1:53:11 PM6/17/14
to argona...@googlegroups.com
We are attempting to use JsonParser.parse on JSON that contains values that are simply NaN.  As a result, we get back -\/("Unexpected content found: NaN")

Is this the correct expected result? 

After locally trying adding a NaN value to the KnownResults and running the JsonParserSpecification tests confirms that this is the case.  We have localized that this result is related to the behavior at line 130 in JsonParser.scala.  Assuming, we could pass that check, however, the logic after would yield that the NaN value would be parsed as null.

If this is actually the expected result, I am slightly confused as there appears to be handling in Json.scala for NaN, +Infinity and -Infinity (i.e. jNumberOrNull, jNumberOrString, etc.)

Thanks for any thoughts!
Jack

seantparsons

unread,
Jun 17, 2014, 5:06:14 PM6/17/14
to argona...@googlegroups.com
Are you talking about NaN values in the JSON to parse? As that's not valid JSON at all.

The handling for NaN in things like jNumberOrNull is for the Double values, as those are not valid to be output as JSON.

Sean.

jack rudnick

unread,
Jun 17, 2014, 5:20:48 PM6/17/14
to argona...@googlegroups.com
Sorry, I will attempt to clarify,

In reality, we are using another library that formats Double NaN into NaN (as a string) in its JSON output.

When we attempt to parse the NaN from this other library's JSON output, using argonaut, we get our errors.  From your description, this is correct functionality.

Is there a more appropriate (less ambiguous) format for expressing Double.NaN that argonaut would more happily parse?

Thanks for looking!
Jack

seantparsons

unread,
Jun 17, 2014, 5:25:04 PM6/17/14
to argona...@googlegroups.com
If you can create an appropriate DecodeJson instance for your NaN values (I can recommend DecodeJson.optionDecoder for that), then you can use the || method with the normal DecodeJson[Double] instance to get a DecodeJson instance that does what you need.

Sean.

Jack Rudnick

unread,
Jun 17, 2014, 5:45:48 PM6/17/14
to argona...@googlegroups.com
Thanks for the quick response!
Reply all
Reply to author
Forward
0 new messages