Deepu
Deepu

Reputation: 1

Extract specific data from JSON string

JSON:

{
  "trackResponse": {
    "shipment": [{
      "warnings": [{
        "code": "TW",
        "message": "Tracking Information Not Found"
      }]
    }]
  }
}

In that string I want to retrieve "message" information. Please let know

Upvotes: 0

Views: 86

Answers (1)

Nonik
Nonik

Reputation: 655

use flatMap and Map

var data = {
  "trackResponse": {
    "shipment": [{
      "warnings": [{
        "code": "TW",
        "message": "Tracking Information Not Found"
      }]
    }]
  }
};
console.log(data.trackResponse.shipment.flatMap(i=>i.warnings.map(m=>m.message)))

Upvotes: 1

Related Questions