cancel
Showing results for 
Search instead for 
Did you mean: 

Some json strings questions

Richard
New Contributor III

Hi
We are just starting off with SnapLogic and we wonder if somebody can give us some answers to the following questions.

We have the following input
[

{

transactionId:“F59AE026-8AEA-4F69-BE97-F7AB981AC3BF”,LineCreationSequenceNumber:1,ItemNumber:“99999999991”,OrderedSalesQuantity:1,SalesPrice:120,AVAPromotionCode:null,SalesUnitSymbol:“UN”,SalesProductCategoryName:null,AVALaserText:null,AVAWrappingText:null,
original:{erpOrderNumber:“JEM-99999”,clientOrderNumber:“00118204”}

},
{
transactionId:“F59AE026-8AEA-4F69-BE97-F7AB981AC3BF”,LineCreationSequenceNumber:2,ItemNumber:“99999999994”,OrderedSalesQuantity:2,SalesPrice:80.93,AVAPromotionCode:null,SalesUnitSymbol:“UN”,SalesProductCategoryName:null,AVALaserText:null,AVAWrappingText:null,
original:{erpOrderNumber:“JEM-99999”,clientOrderNumber:“00118205”}
}
]

I have the following questions

  1. How do we remove the “original” object from the lines with expression language?
  2. How can we remove key "transactionId"and value from the lines with expression language?
  3. Once the original object is removed how can we convert the lines into an array with name “orderLines” with expression language?

Thanks for your help

5 REPLIES 5

j_angelevski
Contributor III

Hello @Richard,

All your requirements can be done with the “Mapper” snap.

To remove any field from the JSON input, you can simply check the “Pass through” option in the Mapper, then in the “Expression” field, write the field from the input that you want removed, but leave the “Target path” empty. This will remove the field from the input object.

image

To remove the field “transactionId” you can do the same as above.

image

I’m not sure which lines you want to convert here into an array, can you elaborate on this ?

Richard
New Contributor III

Thanks for you answers, really appreciate it.

The above lines will have to put in an array if possible.

Further I did try to do your way of removing the original but in my case it worked once but the strange thing is that further on in the pipeline when I tried to do the same thing again it gives me an error that it cannot find the original, even though I can see it in he input schema. Have you seen that before?

Thanks

@Richard ,

If you want to put each object into an array then write the following expression:

sl.ensureArray($.filter((val, key) => key != "original" && key != "transactionId"))

This expression will remove the original and transactionId fields from the input and put all fields into an array.
image

You can check all sl functions here: SL Functions.

If you want to put all objects into a single array then uste the Group by N snap, but change the expression in the Mapper to $.filter((val, key) => key != "original" && key != "transactionId")
image
image

Result:
image

I don’t know about this issue, if there is original in the input schema it should remove it without any problem, try validating the pipeline first and see if there is original object in the output data.

vcocco
New Contributor II

Hi all,
I’m relatively new to JSON. For the example data that Richard provides can someone tell me what the proper syntax is to use in the JSON Generator snap? From the JSON Generator snap I’ve tried to Import the json data and I’m getting errors. One of the errors I’m seeing is 'Verify that the table values and the template are correct".
Thanks,
Vin