0

I have following json pattern

{"property":[{"id":"1","name":"Property 1"},{"id":"2","name":"Property 2"}]}

How can i validate json schema? Thanks in advance.

Rohit13
  • 299
  • 4
  • 16

1 Answers1

1

Use json_decode($string); to convert the JSON string into native PHP. If NULL is returned the string cannot be decoded. You can then use json_last_error() to get the error code, which may be helpful.

http://www.php.net/manual/en/function.json-decode.php

http://www.php.net/manual/en/function.json-last-error.php

Tim
  • 6,281
  • 3
  • 39
  • 49
  • For strict JSON validation, you must use `is_object($result) || is_array($result)`. Simple values like strings or numbers are allowed by `json_decode()` and many other parsers but are not strictly valid JSON. For looser validation checking for `NULL` is fine. – mcrumley Oct 18 '13 at 16:19