I have the ff. JSON payload of an Array
{
"Meta": {
"LastAvailableDateTime": "",
"FirstAvailableDateTime": "",
"TotalPages": 1,
"Count": 2
},
"Links": {
"Next": null,
"Previous": null,
"Self": ""
},
"Data": {
"Transactions": [
{
"AuthCode": "175601",
"CardId": "************8104"
},
{
"AuthCode": "783453",
"CardId": "************8104"
},
{
"AuthCode": "12132",
"CardId": "************8104"
}
]
}
}
And I want to override this payload by renaming CardId to MaskedCardId and adding a new param named CardId with an actual Card id.
My code is the ff. below
var json = //The Parsed JSON Payload;
var CardId = "123458104"
json = JSON.parse(
JSON.stringify(json).split('"CardId":')
.join('"CardId":CardId,"MaskedCardId":')
);
I could already replace the CardId with the renamed parameter named MaskedCardId. with the ff. code
json = JSON.parse(JSON.stringify(json).split('"CardId":').join('"MaskedCardId":'));
But whenever I try to add a new parameter named CardId with a variable value, it is giving an error of.
failed with error: Javascript runtime error: "SyntaxError: Unexpected token: C
How do I make this line of code work with my intended purpose?. TIA