Written by

Deloitte
Question Michael Wood · Mar 18

JSON string field does not have the double quotes

I have a json object coming in on a service with a field that has "NaN" as its value.

"ReferralInOutOfNetworkCd": "NaN",

In my DTL, I do a straight copy. yet what goes outbound is NaN, without being wrapped in double quotes

"consulting_provider_network_ordering_rd":NaN,

Has anyone experience this?  If so, did you find a way to fix or work around it?

Product version: IRIS 2024.1

Comments

DC AI Bot · Mar 18 Bot

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:

  1. JSON Special Values:

    • JSON handles specific special values such as null, true, false, and NaN without enclosing them in double quotes. These values are treated natively and stored as lowercase in JSON structures. Attempting to force double quotes around NaN or similar special values may require additional processing 1.
  2. 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.
  3. 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:

Tell us more:
Don't like the style
Not factually correct
Didn't fully follow instructions
Refused when it shouldn't have
Being lazy
More...
Submit
0 0
Julius Kavay · Mar 18

First, there is no NaN in JSON.

set dynObj = {"val":($double("NAN"))}

write dynObj.val + 123 ---> "NAN

zwrite dynObj

dynObj={"val":($double("NAN"))}  ; <DYNAMIC OBJECT>

/* Question @devcommunity manager: how to exit the "insert code block" function? */

Second, red this for more understanding

0
jaroslav rapp  Mar 19 to Julius Kavay

the new Editor for DC is a nightmare !  

0
Steven Hobbs · Mar 19

The %ToJSON() method of the %DynamicAbstractObject classes in the ObjectScript languageshould never generate NaN without quotation marks.  Although a %DynamicAbstractObject subclass can contain IEEE double-precision floating-point values including the special values Infinity and NaN, using %ToJSON on a %DynamicObject or a %DynamicArray that contains such special values will result in an <ILLEGAL VALUE> error signal since the JSON standard does not support such special IEEE floating-point values.  It is possible some applications have extended the JSON standard to include NaN and Infinity as numeric values without quotation marks, the ObjectScript %ToJSON method does not support such an extension.  However, @Julius Kavay did give an example how the ObjectScript ZWRITE command will display a %DynamicObject entry containing an IEEE NaN value.

0