I have JSON to which i have done JSON.stringify()
to pass the JSON into apex. Now i have one key:value such that value should be passed as array but since i am doing JSON.stringify()
it is converting that array as string. So what can be done to get that "name":"value" from converted JSON string and then send the value as Array.
Format i am excepting.
//Removed some values so that code should not look big.
{
"receivableaccount": "122",
"taxItem": "230",
"shippingitem": "12073",
**"customer_currency":[2,3,4,5,6,8],
**//(This is what i want [2,3,4,5,6,8] should be passed as array instead of string)**
"addressbook": [
{
"addr1": "50 Corriveau Ave.",
"zip": "T8N 3T5",
"city": "St. Albert,",
"country": "CA",
"state": "Alberta"
}
]
}
Code in JS-
finalArr['recordtype'] = recordType;
finalArr['subsidiary'] = subsidary;
finalArr['custentity_customer_type'] = entityCusType;
finalArr['receivableaccount'] = receivableAcc;
finalArr['taxItem'] = taxItem;
finalArr['shippingitem'] = shippingitem;
finalArr['customer_currency'] = customerCurrency;
finalArr['addressbook'] = addrFieldAttr;
jsonBody = JSON.stringify(finalArr);
component.set("v.jsonStr",jsonBody);
console.log('jsonBody of new customer '+jsonBody);
This jsonBody i am directly sending to Apex.
JSON body i am getting through above code.
{
"companyname": "Uk test account",
"custentity_salesforce_id": "153602",
"subsidiary": "1",
"terms": "Net 15",
"recordtype": "customer",
"custentity_customer_type": "2",
"receivableaccount": "122",
"taxItem": "230",
"shippingitem": "12073",
"customer_currency": "[2,3,4,5,6,8]",
"addressbook": [
{
"addr1": "32 Princes Street",
"zip": "EX19 2HD",
"city": "Roborough",
"country": "GB",
"state": ""
}
]
}
customerCurrency
? Without that, we have no idea why it would come in incorrectly. Also, You don't necessarily need to use JSON.stringify+JSON.deserialize, that's usually wasteful programming.JSON.parse
the label, then, as inJSON.parse(customerCurrency)
.finalArr['customer_currency'] = JSON.parse(customerCurrency);
-- Sorry, had to edit this comment.