0

JSON:

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

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

Gabriele Petrioli
  • 191,379
  • 34
  • 261
  • 317
Deepu
  • 1
  • 1
  • Does this answer your question? [Is there a JSON equivalent of XQuery/XPath?](https://stackoverflow.com/questions/8481380/is-there-a-json-equivalent-of-xquery-xpath) – frost-nzcr4 Apr 15 '21 at 21:22

1 Answers1

1

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)))
Nonik
  • 645
  • 4
  • 11