I am attempting to retrieve the currency value from a JSON file and if it is USD, then I want to change it to AUD.
When trying to find the currency attribute in the JSON file, it returned 'undefined' as shown below:
Code:
var datastring = JSON.stringify(data);
var match = /"currency":(^")*/.exec(datastring);
console.log(match ? "Got " + match[1] : "No match");
Output: Got undefined
data.json:
{
"bank":[
{
"bankAccountType":"Saving",
"country":"US",
"currency":"USD",
"firstName":"TestFirstName",
"lastName":"TestLastName",
"confirmed":"true"
}
]
}
Could someone assist me on how to update the currency value in the JSON file and why it is returning 'undefined'?
Thank you for your help.
Updated:
The data.json file is dynamic, with its structure changing every few minutes. My focus is solely on retrieving the currency attribute which is always present in the data.json file and updating the JSON before sending it to the server.