0

I make a curl request to a URL, got this JSON $data back

{"status":200,"message":"Success","data":[{"cpe_mac":"665544332211","device_mac":"223344556677","device_activity":"INACTIVE","dhcp_lease_held":"CONNECTED_DEVICE_DHCP_LEASE_NOT_AVAILABLE","ip_address":"127.0.0.3","vlan_id":1002,"hostname":"babyhost","dhcp_lease_start_time":400,"dhcp_lease_length":600,"interface":"WIRELESS","ssid":"2219","port_ranges":[{"startport":0,"endport":06000:6500}],"last_updated_utc_in_secs":1446061806668}]}

Then, I decode that $raw = json_decode($data, true);

When I print them out I got null:

dd($raw); // null

How can I convert that json to an array and access it?

3
  • If you're running PHP 5.5 or better you can use echo json_last_error_msg(); to see what the error was. Either way you must have malformed JSON. Commented Nov 13, 2015 at 18:56
  • 3
    when you work with JSON; always check it with tool like jsonformatter.curiousconcept.com Commented Nov 13, 2015 at 19:02
  • Will do from now on. Thanks for your advise. I"m new to all of this. Commented Nov 13, 2015 at 19:06

2 Answers 2

2

The json that is returned is invalid

enter image description here

Sign up to request clarification or add additional context in comments.

2 Comments

Would your answer provide any value if the image weren't there? Pictures should illustrate things, not be the entirety of your answer.
Yes, it illustrates where the issue is in the json
2

This part:

[{"startport":0,"endport":06000:6500}]

of your JSON is invalid. The 06000:6500 is not a valid property value. Once I fixed that, json_decode worked properly.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.