Question
· Jun 29

JSON fields and Class properties - are they case sensitive?

Hi noble devs!

Just building a simple frontend->JSON->IRIS backend story, and figured that IRIS while importing via %JSON.Adaptor wants JSON fields to match property names, meaning even should match the case. Like:

{ name: "John", 

surname: "Doe"}

will have issues while saving the dynamic object to a class Sample.Person with:

Class Sample.Person Extends (%Persistent, %JSON.Adaptor)

{

Property Name: %Sting;
Property Surname: %String;
}

As soon as the case is not the same... 

Is there any setting to fix this?) By fixing I mean I want IRIS to don't care about the case JSON fields, as it doesn't matter from SQL point of view, .e.g., IRIS will not allow two same properties but different case:

Property Name : %String;
Property name: %String;

Thoughts?

Product version: IRIS 2025.1
Discussion (15)4
Log in or sign up to continue

To ensure InterSystems IRIS does not care about the case sensitivity of JSON field names when using %JSON.Adaptor, you can utilize the %JSONFIELDNAME parameter. This parameter allows you to define an alias for a property name, mapping it explicitly to the corresponding JSON field name. For example:

Class Sample.Person Extends (%Persistent, %JSON.Adaptor)
{
    Property Name As %String(%JSONFIELDNAME = "name");
    Property Surname As %String(%JSONFIELDNAME = "surname");
}

With this configuration, the fields in JSON { "name": "John", "surname": "Doe" } will correctly map to the properties Name and Surname in the class without any case sensitivity issues [1][2].

Sources:

Hello @Evgeny Shvarov

Unfortunately, when the %JSONFIELDNAME parameter is not explicitly defined, the JSON adaptor treats the property name as a constant, making it fixed and case-sensitive.

However, you can define a custom mapping using an XData block to control how properties are mapped to JSON fields. This provides greater flexibility, and you can even use both %JSONFIELDNAME and XData mappings within the same class.

Example: Custom Mapping with XData

XData OnlyLowercaseTopLevel
{
  <Mapping xmlns="http://www.intersystems.com/jsonmapping">
    <Property Name="Name" FieldName="eventName"/>
    <Property Name="Location" Include="INPUTONLY"/>
  </Mapping>
}
  • Do obj.%JSONImport(dao) Default import (uses standard property names)
  • Do obj.%JSONImport(dao, "OnlyLowercaseTopLevel")Import using a custom mapping

Thank you, @Enrico Parisi ! But are you sure about 1.?

I've just created a class:

Class dc.sample.ObjectScript
{

property Name As %String;
property name as %String;

}

}

And have a compilation error:

ERROR! In class 'dc.sample.ObjectScript' Property 'Name' from 'dc.sample.ObjectScript' and 'name' from 'dc.sample.ObjectScript' have the same name but differ in case.

Yes, pretty sure, that is what is taught in the ISC training courses and what the documentation says:

Description ($PROPERTY)
Property names are case-sensitive

Selecting Fields
Field names in a SELECT statement are not case-sensitive. SqlFieldName names and property names are case-sensitive.

Rules for Class Member Names
Note that the system preserves the case that you use when you define classes, and you must exactly match the case as given in the class definition. However, two class members cannot have names that differ only in case. For example, the identifiers id1 and ID1 are considered identical for purposes of (uniqueness.)