Parse 2d json array using json/retrieve

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • smartinsar
    Member
    • Dec 2021
    • 33

    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
  • yuri
    Member
    • Mar 2014
    • 8623

    #2
    Hi,

    Try this:

    Code:
    $firstName = json\retrieve(
        workflow\lastHttpResponseBody(),
        'items.0.customer_firstname'
    );
    If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

    Comment

    • rabii
      Active Community Member
      • Jun 2016
      • 1263

      #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

      Comment

      • smartinsar
        Member
        • Dec 2021
        • 33

        #4
        Thank you, this one work for me.
        Originally posted by yuri
        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...