You can check if a string contains JSON by decoding it, encoding it again, and comparing the value with the original

You can check if a string contains JSON by decoding it, encoding it again, and comparing the value with the original

🔥 A way to check if a string contains valid JSON: just decode it, encode it again, and check if it matches the original value #php

We're writing a book, you can get it for free here.