HTML get text inside code

I have written this piece of code:

<input id="input" onchange="parseFile(this.files); load();" type="file"><br>
<code id="output"></code>

The function parseFile() (written using nodejs) correctly outputs inside the <code> tag some json data. These info are shown in the display and then I need to load them in an array. So I call the function load that is:

  function load() {

   var dati = document.getElementById('output').innerHTML;
   var myObject = JSON.parse(dati);

   for (var i = 0; i < jsonData.counters.length; i++) {
    var counter = jsonData.counters[i];
    console.log(counter.counter_name);
   }

  }

How can I do this? I need to create an array containing the json data created from the parseFile function that writes in the <code>. I need to extract the data from the code tag. It seems that if I changed the <code> with something else like an input I cannot see the result.

For this reason I need to use the <code> tag. Any idea? I am not very expert of node and javascript.


Example of JSON output:

{ "encryptionConstant": 884583747, "dexNo": 143, "heldItemId": 218, "tid": 26197, "sid": 33357, "exp": 65090, "abilityId": 47, "abilityNum": 2, "superTrainingHitsRemaining": 0, "superTrainingBag": 0, "pid": 1664894422, "natureId": 22, "isFatefulEncounter": false, "gender": "M", "formId": 0, "evHp": 0, "evAtk": 22, "evDef": 110, "evSpe": 2, "evSpAtk": 12, "evSpDef": 0, "contestStatCool": 0, "contestStatBeauty": 0, "contestStatCute": 0, "contestStatSmart": 0, "contestStatTough": 0, "contestStatSheen": 0, "hasCircleMarking": false, "hasTriangleMarking": false, "hasSquareMarking": false, "hasHeartMarking": false, "hasStarMarking": false, "hasDiamondMarking": false, "pokerusDuration": 0, "pokerusStrain": 0, "medalData": 0, "ribbonData": 0, "contestMemoryRibbonCount": 0, "battleMemoryRibbonCount": 0, "distributionSuperTrainingFlags": 0, "nickname": "굃㒹", "move1Id": 667, "move2Id": 111, "move3Id": 133, "move4Id": 122, "move1Pp": 10, "move2Pp": 40, "move3Pp": 20, "move4Pp": 30, "move1Ppu": 0, "move2Ppu": 0, "move3Ppu": 0, "move4Ppu": 0, "eggMove1Id": 0, "eggMove2Id": 0, "eggMove3Id": 0, "eggMove4Id": 0, "canDoSecretSuperTraining": false, "ivHp": 5, "ivAtk": 24, "ivDef": 15, "ivSpe": 7, "ivSpAtk": 28, "ivSpDef": 21, "isEgg": false, "isNicknamed": false, "notOt": "굃㒹", "notOtGender": "M", "currentHandlerIsOt": true, "geoLocation1RegionId": 0, "geoLocation1CountryId": 0, "geoLocation2RegionId": 0, "geoLocation2CountryId": 0, "geoLocation3RegionId": 0, "geoLocation3CountryId": 0, "geoLocation4RegionId": 0, "geoLocation4CountryId": 0, "geoLocation5RegionId": 0, "geoLocation5CountryId": 0, "otGender": "M"}

This is basically a list of data, there aren’t nested arrays. It’s like:

{
 "id": value, 
 "id2": value2,
 "id3": value3
}

You can use array.push method in pure js

array.push(item1, item2, ..., itemX)

which would look like this in a loop

function arrayPushTest() {
    var arrayName = [];
    for (var i = 1; i <= 3; i++) {
        arrayName.push(i);
    }
    alert(arrayName);
}