Search code examples
javascriptarraysjsonnode.jsredips.drag

Extract field from JSON file


I have a JSON file that I want to extract a field from.

{
"player": [
    {
        "Position": "TEST",
        "Name": "TEST",
        "Squad_No": "TEST",
        "Club": "TEST",
        "Age": "TEST"
    },
    {
        "Position": "",
        "Name": "",
        "Squad_No": "",
        "Club": "",
        "Age": ""
    },
    ]
    }

I would like to take the "Name:" field and put it into a file with this format:

[["TEST",0,0,"","TEST"],["ns1.0a",1,0,"","ns1.0a"],
["ns1.1b",2,0,"","ns1.1b"],["ns1.2",3,0,"","ns1.2"]]

The aim is to load this file into a table using the Redips load functionality.

Any ideas on the best method to accomplish this? Any help would be greatly appreciated.


Solution

  • Use map

    arr = arr.player.map( (s,i) => ( [ s.Name , i, 0, "" , s.Name ] ) );