Get Value After Payment - arrays

I have the following object. How do I get the email value from it?
{
"payment_method": "paypal",
"payer_info": {
"email": "example#domain.com",
"first_name": "example",
"last_name": "xxx",
"payer_id": "12313213",
"shipping_address": {
"recipient_name": "Example",
"id": "5435345",
"line1": "1 SS ",
"city": "San Jose",
"state": "CA",
"postal_code": "95131",
"country_code": "US"
},
"phone": "4547567",
"country_code": "US"
}
}

Related

How to Break json object in a for each

How can one split the below json example by different email in a for each loop? So the end result is two completely separate entities keeping there own objects and arrays.
This result comes from a sql dump but the sql connector alters the output, so I've had to parse that output in a for each loop of its own even though there is no loop it's all in one line.
[
{
"Email": "Steve#gmail.com",
"Name": "Steve Larson",
"ID": "1111",
"Date": "2022-09-12",
"Address": "10 Chicken Place",
"Town": "Gatebody",
"Postcode": "xxx 1xx",
"Data": [
{
"Ref": "34546",
"Transaction_Date": "2018-11-29",
"Amount": 27.76,
"Balance": 27.76,
"Notes": "Beep1"
},
{
"Ref": "34546v2",
"Transaction_Date": "2018-12-24",
"Amount": 27.76,
"Balance": 27.76,
"Notes": "Beep2"
}
]
},
{
"Email": "innis#gmail.com",
"Name": "Innis Blitz",
"ID": "3456",
"Date": "2022-10-12",
"Address": "33 Snake Road",
"Town": "March",
"Postcode": "cxc 3cd",
"Data": [
{
"Ref": "078776701",
"Transaction_Date": "2021-08-27",
"Amount": 984.68,
"Balance": 984.68,
"Notes": "Yes please"
},
{
"Ref": "078776701v2",
"Transaction_Date": "2021-08-27",
"Amount": 98422.6,
"Balance": 98432.6,
"Notes": "Please not now"
}
]
}
]
Would like to do a for each so it splits the above like so. The idea then for my to load the result of the for each into a template that takes arrays.
{
"Email": "Steve#gmail.com",
"Name": "Steve Larson",
"ID": "1111",
"Date": "2022-09-12",
"Address": "10 Chicken Place",
"Town": "Gatebody",
"Postcode": "xxx 1xx",
"Data": [
{
"Ref": "34546",
"Transaction_Date": "2018-11-29",
"Amount": 27.76,
"Balance": 27.76,
"Notes": "Beep1"
},
{
"Ref": "34546v2",
"Transaction_Date": "2018-12-24",
"Amount": 27.76,
"Balance": 27.76,
"Notes": "Beep2"
}
]
}
{
"Email": "innis#gmail.com",
"Name": "Innis Blitz",
"ID": "3456",
"Date": "2022-10-12",
"Address": "33 Snake Road",
"Town": "March",
"Postcode": "cxc 3cd",
"Data": [
{
"Ref": "078776701",
"Transaction_Date": "2021-08-27",
"Amount": 984.68,
"Balance": 984.68,
"Notes": "Yes please"
},
{
"Ref": "078776701v2",
"Transaction_Date": "2021-08-27",
"Amount": 98422.6,
"Balance": 98432.6,
"Notes": "Please not now"
}
]
}
I have reproduced in my environment and got expected results and I followed below process:
I have initialized your input as below:
Then i added for each control and send the output of previous step as input as inside of foreach loop, i have added send email action.
Outputs:
I have got tow jsons in two seperate emails as above.

How to get values from object as an array

We need to convert the object to an Array of objects and do map on the field but the field is incremental like field1, field2 which is where we got stuck.
I tried the below code:
output application/json
---
payload.main.field map(value) -> {
"name": value.name,
"age": value.age,
"location": value.location[0].country
}
Input:
{
"main": {
"field1": {
"name": "value",
"age": 20,
"address": {
"location": [
{
"country": "US",
"zipcode": 1234
},
{
"country": "US",
"zipcode": 1234
}
]
}
},
"field2": {
"name": "pqr",
"age": 23,
"address": {
"location": [
{
"country": "CA",
"zipcode": 1235
},
{
"country": "US",
"zipcode": 1234
}
]
}
},
"field3": {
"name": "abc",
"age": 22,
"address": {
"location": [
{
"country": "BU",
"zipcode": 1236
},
{
"country": "US",
"zipcode": 1234
}
]
}
}
}
}
For the above Input, Below is the expected response.
Expected Output:
{
"main": [
{
"name": "value",
"age": 20
"location": "US"
},
{
"name": "pqr",
"age": 23
"location": "CA"
},
{
"name": "abc",
"age": 22
"location": "BU"
}
]
}
For location, it will be like location[0].country when the array size is not 0 and country not null.
output application/json
---
main : payload.main pluck $ map {
"name": $.name,
"age": $.age,
"location": if( sizeOf($.address.location) !=0) $.address.location[0].country else "N/A"
}

How to create a JSON structure in ReactJS

I have a use-case to create a JSON structure in React in order to POST an API request. The JSON structure body contains objects and arrays.
Please let me know how to create it in ReactJS.
Below is the sample JSON structure that needs to be created using ReactJS:-
{
"transactionAmount": {
"currency": "INR",
"value": 1220.38
},
"transactionDate": "2020-05-18T00:00:00Z",
"tripData": {
"agencyBooked": false,
"legs": [
{
"endLocation": {
"countryCode": "IN",
"city": "Delhi",
"name": "Indira Gandhi International"
},
"startDate": "2020-05-22",
"startTime": "08:00",
"returnLeg": false,
"startLocation": {
"countryCode": "US",
"city": "San Francisco",
"name": "San Francisco International"
},
"endTime": "21:00",
"endDate": "2020-05-22",
"startLocationDetail": "none"
},
{
"endLocation": {
"countryCode": "US",
"city": "San Francisco",
"name": "San Francisco International"
},
"returnLeg": true,
"startDate": "2020-05-24",
"startLocation": {
"countryCode": "IN",
"city": "Delhi",
"name": "Indira Gandhi International"
},
"startTime": "17:00"
}
],
"segmentType": {
"category": "REQ_SEG_AIRFR",
"code": "AIRFR"
},
"selfBooked": false,
"tripType": "ROUND_TRIP"
}
}
You can simply make a JSON format like this.
const dummyObject = {
name: 'Dummy',
age: 22,
about: {
hobbies: ['soccer']
},
works: true
}

json array character value ascending and descending order typescript

I have an array like the following:
var homes = [
{
"h_id": "3","city": "Dallas","state": "YYYY","zip": "75201","price": "162500"
},
{
"h_id": "4","city": "CA","state": "ZZZZ","zip": "90210","price": "319250"
},
{
"h_id": "5","city": "New York","state": "AAAA","zip": "00010","price": "962500"
},
{
"h_id": "5","city": "New York","state": "CCCC","zip": "00010","price": "962500"
}
];
I need to sort it so i can be able to check state in both ascending and descending order,
The result needed as following:
var homes = [
{
"h_id": "5", "city": "New York", "state": "AAAA", "zip": "00010", "price": "962500"
},
{
"h_id": "5", "city": "New York", "state": "CCCC", "zip": "00010", "price": "962500"
},
{
"h_id": "3", "city": "Dallas", "state": "YYYY", "zip": "75201", "price": "162500"
},
{
"h_id": "4", "city": "CA", "state": "ZZZZ", "zip": "90210", "price": "319250"
},
];
homes = homes .sort(function (a, b) {
return a.name.localeCompare(b.state);
});
You can use city,h_id etc in place of state

Need help in fetching specific Objects from JSON array

I have a JSON array in the following format, and I need to fetch the objects that belong to the same country i.e having the same value for the "country" key or "country_short" key in my JSP. Could any one please help?
[{
"country_short": "USA",
"city": "Butler",
"description": "",
"date_new": "2016-09-27 21:26:23",
"url": "--",
"country": "United States",
"company": "Cargill",
"title": "Yard Driver",
"reqid": "BUT00451",
"state": "Wisconsin",
"state_short": "WI",
"location": "Butler, WI",
"guid": "04F2182583FC429BBAEF8B86F8467A55",
"uid": null
}, {
"country_short": "CAN",
"city": "Camrose",
"description": "",
"date_new": "2016-09-27 21:26:23",
"url": "--",
"country": "Canada",
"company": "Cargill",
"title": "Agronomy Associate",
"reqid": "CAN00437",
"state": "Alberta",
"state_short": "AB",
"location": "Camrose, AB",
"guid": "9FB7383A512F48F893C535765F9FBE4F",
"uid": null
}]
Thanks in Advance!
You can use the JS filter method like this
a.filter(function(item){ return item.country_short.toLowerCase() == 'usa'});

Resources