cancel
Showing results for 
Search instead for 
Did you mean: 

Help with adding a field in JSON output

negi_sagar
New Contributor II

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.

2 ACCEPTED SOLUTIONS

Aleksandar_A
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

negi_sagar
New Contributor II

Thank you Aleksandar for answering this quickly and it worked.

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

View solution in original post

2 REPLIES 2

Aleksandar_A
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 II

Thank you Aleksandar for answering this quickly and it worked.

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