Announcement

Collapse
No announcement yet.

Parse 2d json array using json/retrieve

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Parse 2d json array using json/retrieve

    Hello,
    i'm newbee and not so good at programming.

    I receive json array from $_lastHttpResponseBody looking like this:

    {
    "items": [
    {
    "customer_firstname": "John doe",
    "increment_id": "1000000019",
    "status": "canceled",
    "total_paid": 198
    }
    ]
    }

    is it possible to get to the 'customer_firstname' using json\retrieve ?
    Thank you

  • #2
    Hi,

    Try this:

    Code:
    $firstName = json\retrieve(
        workflow\lastHttpResponseBody(),
        'items.0.customer_firstname'
    );

    Comment


    • #3
      Hi @smartinsar

      You can also use Dot notation to access elements within arrays, it worked for me, see code below:

      Code:
      $customerFirstName = json\retrieve($_lastHttpResponseBody, 'items.customer_firstname');
      Rabii
      Web Dev | Freelancer

      Comment


      • #4
        Thank you, this one work for me.
        Originally posted by yuri View Post
        Hi,

        Try this:

        Code:
        $firstName = json\retrieve(
        workflow\lastHttpResponseBody(),
        'items.0.customer_firstname'
        );

        The second one not working =(

        Thanks a lot for your help guys.

        Comment

        Working...
        X