The issue originates from how JSON handles numeric and special values like “NaN”. These values are not enclosed in double quotes in JSON serialization. Here are key insights and a possible resolution:
-
JSON Special Values:
- JSON handles specific special values such as
null,true,false, andNaNwithout enclosing them in double quotes. These values are treated natively and stored as lowercase in JSON structures. Attempting to force double quotes aroundNaNor similar special values may require additional processing 1.
- JSON handles specific special values such as
-
Serialization Approach:
- Some serialization methods (like
%ZEN.Auxiliary.jsonProvider) have parameters to control how values are serialized. In older methods, numeric values might always be treated as numbers regardless of their original property type unless additional adjustments are made to override this behavior 2.
- Some serialization methods (like
-
Custom Handling Approach:
-
You can manage this serialization issue by explicitly treating properties like strings in your custom classes. This ensures that numbers or special values are always serialized enclosed in double quotes. For example:
Class dc.Test Extends %RegisteredObject { Property Value As %String; }When outputting the JSON stream:
set object = ##class(dc.Test).%New() set object.Value = "NaN" set stream = ##class(%ZEN.Auxiliary.jsonProvider).%WriteJSONStreamFromObject(.json, object)
-
This ensures proper quoting for numeric or string values while maintaining standard JSON behavior for “NaN” and similar special values 2.
Let me know if you need a deeper explanation or examples to refine your handling further!
Sources:
- Log in to post comments