53
Views
10
Comments
JSON serialization it's not working as expected
Application Type
Reactive
Service Studio Version
11.55.24 (Build 64186)
Platform Version
11.33.0 (Build 44426)

Hi Team,

I'm trying to perform JSON serialization, but it's not working as expected. I have a structure with attributes like IsSelect and IsCheck, which I am assigning as False. However, after serialization, my JSON string is coming out empty.

Thanks in advance for your help!

Output at UI- 


2026-01-28 16-57-48
Mihai Melencu
Champion

Hi Rahul,

Did you turn on the Serialize Default Values property? Boolean False value is considered default.

Example:

2020-01-08 08-43-00
Rahul Kumar

Hi @Mihai Melencu ,Thank you for your reply. I don't want to serialize default values. I only want to serialize the attributes that I explicitly assign, whether the value is false or true. 

2026-01-28 16-57-48
Mihai Melencu
Champion

Hi, in that case you can set the attributes that you need as mandatory. This will ensure the attribute is always included.

2020-01-08 08-43-00
Rahul Kumar

However, that's not the case for my situation. I need to send this JSON in an API request, and sometimes I need to include this structure in the request, while other times I do not. If I set "IsMandatory" to "Yes," the object is always included in the JSON, which is not what I want.

Another issue is that it's now requiring a value throughout the application, which causes errors in places where it was already being used.

JSON serialization was working properly before, but this issue has started happening recently.

2026-03-12 06-20-48
KUNDAN CHAUHAN
Champion

@Rahul Kumar â€” I understand how the default behavior of JSON serialization in OutSystems can cause unexpected issues, especially when working with optional fields in API payloads.

In my opinion, one of the cleanest and most maintainable workarounds is to use two separate structures:

1.One structure that includes the optional field(s) or nested object(s)

2.Another structure that excludes them completely

This approach gives you full control at design time and allows you to decide at runtime which structure to populate and serialize based on your logic.


2020-01-08 08-43-00
Rahul Kumar

This approach isn’t the cleanest or most maintainable.

In the driver module, I have a main structure that contains many nested structures. If we create separate structures just for this purpose, it will result in many duplicate structures with similar names (e.g., FirstAttr2). Since multiple developers are working on this, it will be difficult for them to identify which structure to use. For example, if someone needs to add a new field, they won’t know which duplicate structure to update or understand the purpose of the others. I’m already aware of this workaround, but it introduces confusion and maintainability issues.

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

Hi Rahul,

What you want is a tri-state: not assigned, True or False. This is simply not possible with OutSystems out of the box, and has never been possible. Regardless of what you claim, there hasn't been any change in how OS handles these things. On a low level, the Platform does not keep track of whether a value has been explicitly assigned or not.

The only way to handle this is change the Boolean to a Text, and in the On Before Request manipulate the JSON so that if the Text is empty, you remove the attribute completely, and if it's "True" or "False" you change it to true or false respectively.

2021-10-09 07-57-44
Stefan Weber
 
MVP

Dourine Boudry wrote a very good article on implementing a Trilean. See here.

2024-03-11 09-26-19
Rahul Shrivastava

Hi Rahul Kumar,

It's totally depends on what is the Default Value of structure's Attribute, If the default value of structure's attribute is True it will not be appear in JSON serialize string for true. and same as for  false as you have mentioned in your query.

if you want to get JSON serialize string in all the cases you have to select YES for JSONSerialize Default Value.



2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

The OP explained that that is not his problem, and others have already answered his question. Please read questions carefully, and also other answers, before replying.

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.