cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Help with adding a field in JSON output

negi_sagar
New Contributor

I have a JSON output like this:

{
"Choices":
{
"1":
{
"Display":"Generating standard, automated reports (e.g. ERP, reporting tools)?"
}
"2":
{
"Display":"Generating non-standard / custom reports (e.g. spreadsheets)?"
}
"3":
{
"Display":"Responding to Ad Hoc data requests?"
}
"4":
{
"Display":"Reconciling, combining, or manipulating data across multiple systems, reports, tools, and excel sheets?"
}
"5":
{
"Display":"Analyzing data and building insights?"
}
"6":
{
"Display":"Other"
}
}
"QuestionText_Unsafe":
"Tools and Reporting</br></br>On an average, what percentage of your time in a given week is spent:"
"DisplayDataExportTag":
null
"DisplayLogic":
null}

This is one of the result and have multiple like this.

So here I have this Field โ€œChoicesโ€ where I have these values in numbers then another Child Field โ€œDisplayโ€

Now I want antoher field with Display which will be TextEntry: โ€œtrueโ€ but only for the last one or the max one.

So for eg: here in choices the last/max field is 6:

"6":
{
"Display":"Other"
}

It should be like this:

"6":
{
"Display":"Other",
"TextEntry":"true"
}

How do I do that? Iโ€™m new to the language.

1 ACCEPTED SOLUTION

AleksandarAngel
Contributor III

Hello @negi_sagar,

You can try by using a Mapper Snap with Pass-through enabled:
image

For Choices try using the below expression:

$Choices.extend({[Math.max(...$Choices.keys().map(x => parseInt(x))).toString()]:$Choices.get(Math.max(...$Choices.keys().map(x => parseInt(x))).toString()).extend({"TextEntry":"true"})})

Sample pipeline:
SL-comm-add-field-to-max-in-json_2023_03_20.slp (4.4 KB)

Let me know if this helps you.

BR,
Aleksandar.

View solution in original post

2 REPLIES 2

AleksandarAngel
Contributor III

Hello @negi_sagar,

You can try by using a Mapper Snap with Pass-through enabled:
image

For Choices try using the below expression:

$Choices.extend({[Math.max(...$Choices.keys().map(x => parseInt(x))).toString()]:$Choices.get(Math.max(...$Choices.keys().map(x => parseInt(x))).toString()).extend({"TextEntry":"true"})})

Sample pipeline:
SL-comm-add-field-to-max-in-json_2023_03_20.slp (4.4 KB)

Let me know if this helps you.

BR,
Aleksandar.

negi_sagar
New Contributor

Thank you Aleksandar for answering this quickly and it worked.

Can you tell me some resources from where I learn to create these expressions?