kyamagu / matlab-json

Use official API: https://mathworks.com/help/matlab/json-format.html
Other
52 stars 15 forks source link

Added support for NaN value. #3

Closed Strasser-Pablo closed 8 years ago

Strasser-Pablo commented 9 years ago

This support is added by converting NaN value to NaN string. Note that when converting back to matlab NaN string will be considered as NaN number.

kyamagu commented 9 years ago

@Strasser-Pablo This will be an invalid JSON conversion, as there is no NaN nor Infinity in the JSON specification. See this. What would you do if one wants to convert "NaN" as a string? Although I understand that JSON should bring a better floating point number support, I won't accept this workaround to break the JSON specification.

Perhaps a better approach is to follow Python's approach, where one can specify an option flag to enable/disable Infinity/NaN support in conversion.

Strasser-Pablo commented 9 years ago

Yes, I believe adding a flag to support NaN and Infinity would be a good Idea. I will have a look at it. The NaN conversion worked well for my use case. Thanks for the answer.