Announcement: You can find the guides for Commerce 7.5 and later on the new Elastic Path Documentation site. This Developer Center 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.

{
  "self": {
    "type": "elasticpath.carts.cart",
    "uri": "/commerce-legacy/carts/mobee/guz=?zoom=lineitems,total",
    "href": "http://api.elasticpath.net/cortex/carts/mobee/guz=?zoom=lineitems,total"
  },
  "total-quantity": 3,
  "links": [
    {
      "rel": "lineitems",
      "rev": "cart",
      "type": "elasticpath.collections.links",
      "uri": "/commerce-legacy/carts/mobee/guz=/lineitems",
      "href": "http://api.elasticpath.net/cortex/carts/mobee/guz=/lineitems"
    },
    {
      "rel": "order",
      "rev": "cart",
      "type": "elasticpath.orders.order",
      "uri": "/commerce-legacy/orders/mobee/mu3=",
      "href": "http://api.elasticpath.net/cortex/orders/mobee/mu3="
    },
    {
      "rel": "total",
      "rev": "cart",
      "type": "elasticpath.totals.total",
      "uri": "/commerce-legacy/totals/carts/mobee/guz=",
      "href": "http://api.elasticpath.net/cortex/totals/carts/mobee/guz="

    }
  ],
  
  "_lineitems": [
    {
      "self": {
        "type": "elasticpath.collections.links",
        "uri": "/commerce-legacy/carts/mobee/guz=/lineitems",
        "href": "http://api.elasticpath.net/cortex/carts/mobee/guz=/lineitems"
      },
      "links": [
        {
          "rel": "element",
          "rev": "list",
          "type": "elasticpath.carts.line-item",
          "uri": "/commerce-legacy/carts/mobee/guz=/lineitems/hfq=",
          "href": "http://api.elasticpath.net/cortex/carts/mobee/guz=/lineitems/hfq="
        },
        {
          "rel": "element",
          "rev": "list",
          "type": "elasticpath.carts.line-item",
          "uri": "/commerce-legacy/carts/mobee/guz=/lineitems/gbq=",
          "href": "http://api.elasticpath.net/cortex/carts/mobee/guz=/lineitems/gbq="
        },
        {
          "rel": "cart",
          "rev": "lineitems",
          "type": "elasticpath.carts.cart",
          "uri": "/commerce-legacy/carts/mobee/guz=",
          "href": "http://api.elasticpath.net/cortex/carts/mobee/guz="
        }
      ]
    }
  ],
  "_total": [
    {
      "self": {
        "type": "elasticpath.totals.total",
        "uri": "/commerce-legacy/totals/carts/mobee/guz=",
        "href": "http://api.elasticpath.net/cortex/totals/carts/mobee/guz="
      },
      "cost": [
        {
          "amount": 211,
          "currency": "CAD",
          "display": "$211.00"
        }
      ],
      "links": [
        {
          "rel": "cart",
          "rev": "total",
          "type": "elasticpath.carts.cart",
          "uri": "/commerce-legacy/carts/mobee/guz=",
          "href": "http://api.elasticpath.net/cortex/carts/mobee/guz="
        }
      ]
    }
  ]
  
}
Table 1. JSONPath Examples
Example JSONPath Result
Extract the total-quantity child property.
$total-quantity
[
  3
]
Extract every quantity value nested in other properties.
$..quantity
[
  2,
  1
]
Extract the first element of the total cost array.
$_total..cost[0]
[
  {
    "amount": 211,
    "currency": "CAD",
    "display": "$211.00"
  }
]