Php

Asked • 05/26/19

Fastest way to check if a string is JSON in PHP?

I need a really, really fast method of checking if a string is JSON or not. I feel like this is not the best way: function isJson($string) { return ((is_string($string) && (is_object(json_decode($string)) || is_array(json_decode($string))))) ? true : false; } Any performance enthusiasts out there want to improve this method?

1 Expert Answer

By:

Sajan P. answered • 11/02/20

Tutor
New to Wyzant

CTO at Enterprise PHP Software Company

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.