Question about mapping a JSON field in FlexMonster

Answered
Diga Tecnologias asked on September 18, 2024

Hello FlexMonster team,

I am encountering an issue related to mapping a JSON field in my dataset and would appreciate your assistance.

I have a field called services that contains a list of JSON objects, as shown in the example below:

"services": [ { "service_name": "Abertura de conta", "service_time": 8 }, { "service_name": "Consórcio", "service_time": 9 } ]

I would like to display this field in a FlexMonster table. However, I couldn't find a way to map fields of this type in the documentation, as referenced on this page. Is there a way to display the data contained in the services field, or could you recommend any workaround for handling nested JSON structures?

Thank you in advance for your help!

Best regards,
Diga

4 answers

Public
Solomiia Andrusiv Solomiia Andrusiv Flexmonster September 19, 2024

Hello, Diga!

Thank you for reaching out to us.

Kindly note that the JSON data needs to be flattened before embedding it in Flexmonster. For example, like this:

[
{
"service.service_name": "Abertura de conta",
"service.service_time": 8,
},
{
"service.service_name": "Consórcio",
"service.service_time": 9,
},
]

If you want fields to be visually grouped on the UI, you can add a "Service" folder in mapping, so then the fields would be grouped in the Field List: https://jsfiddle.net/flexmonster/co1ews98/.

Hope you will find our answer helpful.
Feel free to reach out to us in case of any other questions.

Kind regards,
Solomiia

Public
Diga Tecnologias September 19, 2024

Hello Solomiia,

Thank you for your prompt response.

I understand that flattening the JSON structure is one approach, but my goal is to display the services field as an array within each entry, maintaining the structure as shown below:

{
"company_id": 42,
"unit_group_id": 664,
"services": [
{
"service_name": "Abertura de conta",
"service_time": 8
},
{
"service_name": "Consórcio",
"service_time": 9
}
]
}

I’ve created a more detailed example of what I am trying to achieve using this JSFiddle: https://jsfiddle.net/58mpkqz1/6/.

Is there any way to map the services array as part of the dataset, or any other suggested solution that would allow me to keep the nested structure?

Thank you again for your support, and I look forward to your insights.

Kind regards,
Diga

Public
Solomiia Andrusiv Solomiia Andrusiv Flexmonster September 20, 2024

Hello, Diga!

Thank you for your swift response.

Please note that flattening JSON before embedding it in Flexmonster is the only available approach, as Flexmonster works only with flat JSON format. If you want first-level fields from your sample, e.g. company_id, to be shown in Flexomonster as well as nested ones, the data should look as follows:

[
{
"service.service_name": "Abertura de conta",
"service.service_time": 8,
"company_id": 42,
"unit_group_id": 664,
},
{
"service.service_name": "Consórcio",
"service.service_time": 9,
"company_id": 42,
"unit_group_id": 664,
},
]

We have prepared a JSFiddle sample to illustrate the idea: https://jsfiddle.net/flexmonster/1brxnjvf/.

However, if you want to show in Flexmonster only Services data, it is possible to specify the nested level using dataRootPath property, e.g.:

dataSource: {
type: "json",
filename: //path to your JSON file,
dataRootPath: "Services"
},

Then, Flexmonster would only work with flat JSON content of the Services array. Here is the JSFiddle for reference: https://jsfiddle.net/flexmonster/bd2oqvLm/.

Hope you will find our answer helpful.

Kind regards,
Solomiia

Public
Solomiia Andrusiv Solomiia Andrusiv Flexmonster September 26, 2024

Hello, Diga!

Hope you are doing well.

Our team is wondering if you have any further questions about nesting JSONs in Flexmonster.

Looking forward to hearing from you.

Kind regards,
Solomiia

Please login or Register to Submit Answer