Home > front end >  How to read and write an external local JSON file in JavaScript?
How to read and write an external local JSON file in JavaScript?

Time:08-13

I have a JSON file and I can change the value of "src" and "composition" but I can not change the value of actions/postrender/second output value.

I am using this js

file.template.src = "value1";
file.template.composition= "value2";
file.actions.postrender.output= "value3";
{
    "template": {
        "src": "value1",
        "composition": "value2"
    },
    "actions": {
        "postrender": [
            {
                "module": "@nexrender/action-encode",
                "preset": "mp4",
                "output": "encoded.mp4"
            },
            {
                "module": "@nexrender/action-copy",
                "input": "encoded.mp4",
                "output": "d:/mydocuments/results/myresult.mp4"
            }
        ]
    }
}

CodePudding user response:

file.actions.postrender.output= "value3"; Doesn't work because postrender is an array.

You need to specify which element you want to modify (0 for the first element, or 1 for the second element):

file.actions.postrender[0].output= "value3";
file.actions.postrender[1].output= "value3";

CodePudding user response:

Thats because you are not selecting the second element in the array. Use the index operator to first get the second element and then modify the value:

file.actions.postrender[1].output= "value3";

CodePudding user response:

It is because te value of the key "postrender" is an array.

To update the key "output" of an element of the array you should select which element, for example:

file.actions.postrender[0].output= "value3";

If you want to update all of the elements you could use a for loop.

  • Related