Here is a JsonObject snippet in question:
let jsonObject = {
"augmentedReality": {
"enabled": false,
"augmentedRealitySettings" : [
{
"assetId": 7
}
]
}
}
I have created a recursive function as shown below:
isAssetId(jsonObject: any) {
for (let key in jsonObject) {
if (typeof jsonObject[key] === "object") {
jsonObject[key] = this.isAssetId(jsonObject[key]);
} else {
if(key=='assetId'){
jsonObject[key]=3;
}} }
return jsonObject;
}
The aim is to modify the assetId wherever it exists in the jsonObject. However, after executing the code, the output JSON object is not as expected.
I called the function using:</p>
jsonObject= isAssetId(jsonObject);
console.log(jsonObject);
The resulting output is:
{
augmentedReality: { enabled: false, augmentedRealitySettings: [
[Object] ] }
}
The Object
should display the actual data rather than just saying "Object". I am puzzled about what could be causing this issue. Any assistance would be greatly appreciated.
UPDATE:
I tested the code on the following platform:
here
Interestingly, it works fine there but encounters issues when used within my typescript code on NestJs
. What could possibly be the reason for this inconsistency?