140
Views
3
Comments
How can I dynamically display a structure's data but only show non-empty values?
Application Type
Traditional Web

I have a JSON object that I'm deserializing into an OS structure. Depending on the data, sometimes there are fields in the JSON that are empty. Is there a way I can dynamically display this data and skip over the key-value pairs that have empty values?

For example, say I have the following JSON object: [{"FirstName":"John","MiddleName":"","LastName":"Smith","Email":"","Number":"123456789"}] 

And I want to display this information in a label-value format, such as:

  • First Name: John
  • Middle Name:
  • Last Name: Smith
  • Email: 
  • Number: 123456789

I need a structure with all five values to be able to deserialize it, especially since sometimes there will be values for middle name and email. However, when those fields (or any fields) are empty, I'd like to display this information but completely skip over the empty fields, so that it looks like this:

  • First Name: John
  • Last Name: Smith
  • Number: 123456789

Is there a way to do this dynamically? I know I can create all the labels and set conditions for them depending on if the values exist, but that requires me to do that for each individual field and I have many. I'm hoping there's a way to set this up to do it automatically, especially so I can add or remove fields in the future and don't have to edit the list myself every time.

2023-04-06 11-24-23
Paulo Zacarias

Hi Joseph, 

So, If I understood your concern, it's about the performance. 

You want to avoid the iteration of all these attributes for each individual and check if any of the attributes are empty because if so, you would not append the key-value pair to the list that is displayed on the UI.

Perhaps you can make use of CSS with some conditions to hide/display the key-value pair. For instance, create a web block that receives the individual information (empty values also) and then, wrap each key-value pair with a div that will be hidden or displayed based on the value's value.

Your UI will be a list of the web block created above.

Does this fulfil your requirement?

Regards, 

PZ 

2020-09-18 09-37-36
Devendra Baghel

Hi 

Joseph Kuhn

You can first convert your JSON to Key Value pair by using ardoJSON listfy method 

use below URL to test

https://jnb.outsystemscloud.com/ardoJSONReactiveDemo/JSON_Listify

This will convert your JSON into below format

[{"key":"FirstName","value":"John"},{"key":"MiddleName","value":""},{"key":"LastName","value":"Smith"},{"key":"Email","value":""},{"key":"Number","value":"123456789"}] 

Now you can write a logic if value is blank than don't show it. Hope this would help

Regards

Devendra




UserImage.jpg
Joseph Kuhn

Is this any different from using the build in serialize and deserialize actions? It seems like it would do the same thing and leave me with the same problem.

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