0

I was using wit.ai's JSON to get the data and recently they changed the structure. This is how it looks

"entities": {
  "paraName:paraName": [
     {
        "id": "1266de86-97af-434b-95ee-f87ff58c935a",
        "name": "paraName",
        "role": "paraName",
        "start": 30,
        "end": 34,
        "body": "data",
        "confidence": 0.549,
        "entities": [

        ],
        "suggested": true,
        "value": "data",
        "type": "value"
     },
     {
        "id": "1266de86-97af-434b-95ee-f87ff58c935a",
        "name": "paraName",
        "role": "paraName",
        "start": 39,
        "end": 45,
        "body": "height",
        "confidence": 0.8922,
        "entities": [

        ],
        "value": "height",
        "type": "value"
     }
  ]

}

This is how I am trying to get the value of those parameters (i.e. data, and height)

    let data = response.entities;
    let paraMeter = data.paraName.map(function(res){
        return res['value'];
    })
    keyValues = paraMeter.join().split(',');

but I am getting Cannot read property 'map' of undefined error. Anyone knows what's wrong here?

Thank you

Binita Gyawali
  • 256
  • 2
  • 13

1 Answers1

1

You can refer the key like shown in this snippet:

let paraMeter = data["paraName:paraName"].map(function(ref){

More details here :

Properties of JavaScript objects can also be accessed or set using a bracket notation (for more details see property accessors). Objects are sometimes called associative arrays, since each property is associated with a string value that can be used to access it.

let response = {"entities": {
  "paraName:paraName": [
     {
        "id": "1266de86-97af-434b-95ee-f87ff58c935a",
        "name": "paraName",
        "role": "paraName",
        "start": 30,
        "end": 34,
        "body": "data",
        "confidence": 0.549,
        "entities": [

        ],
        "suggested": true,
        "value": "data",
        "type": "value"
     },
     {
        "id": "1266de86-97af-434b-95ee-f87ff58c935a",
        "name": "paraName",
        "role": "paraName",
        "start": 39,
        "end": 45,
        "body": "height",
        "confidence": 0.8922,
        "entities": [

        ],
        "value": "height",
        "type": "value"
     }
  ]}
  };
  
  let data = response.entities;
    let paraMeter = data["paraName:paraName"].map(function(ref){
        return ref['value'];
    })
    keyValues = paraMeter.join().split(',');
    console.log(keyValues);
takrishna
  • 4,884
  • 3
  • 18
  • 35