code-8
code-8

Reputation: 58662

JSON Decode return NULL

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?

Upvotes: 0

Views: 264

Answers (2)

Pierre
Pierre

Reputation: 1583

The json that is returned is invalid

enter image description here

Upvotes: 2

Sean Bright
Sean Bright

Reputation: 120644

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.

Upvotes: 2

Related Questions