Announcement: You can find the guides for Commerce 7.5 and later on the new Elastic Path Documentation site. This site contains the guides for Commerce 6.13.0 through 7.4.1.Visit new site

This version of Elastic Path Commerce is no longer supported or maintained. To upgrade to the latest version, contact your Elastic Path representative.

Parsing Responses

Parsing Responses

JSONPath is a tool that makes it easier to write code that selects and extracts data from JSON. For a complete usage guide, see JSONPath.

Example: Extracting Data from a Cart

In this example, zoom retrieved the cart resource and its corresponding lineitems and total resources. Once the client application receives the response, JSONPath can extract the data you're interested in.

  1. {
  2. "self": {
  3. "type": "elasticpath.carts.cart",
  4. "uri": "/commerce-legacy/carts/mobee/guz=?zoom=lineitems,total",
  5. "href": "http://api.elasticpath.net/cortex/carts/mobee/guz=?zoom=lineitems,total"
  6. },
  7. "total-quantity": 3,
  8. "links": [
  9. {
  10. "rel": "lineitems",
  11. "rev": "cart",
  12. "type": "elasticpath.collections.links",
  13. "uri": "/commerce-legacy/carts/mobee/guz=/lineitems",
  14. "href": "http://api.elasticpath.net/cortex/carts/mobee/guz=/lineitems"
  15. },

Copy

...
Read more

Table 1. JSONPath Examples
Example JSONPath Result
Extract the total-quantity child property.
  1. $total-quantity

Copy

  1. [
  2. 3
  3. ]

Copy

Extract every quantity value nested in other properties.
  1. $..quantity

Copy

  1. [
  2. 2,
  3. 1
  4. ]

Copy

Extract the first element of the total cost array.
  1. $_total..cost[0]

Copy

  1. [
  2. {
  3. "amount": 211,
  4. "currency": "CAD",
  5. "display": "$211.00"
  6. }
  7. ]

Copy