I have a variable $image, Sometimes it containes JSON Encoded value and sometimes it is not. What I need? If $image doesn't have JSON encoded data, I want to do my custom code.

I am trying this:

public function isJSON($string){
    return is_string($string) && is_array($this->jsonHelper->jsonDecode($string, true)) && (json_last_error() == JSON_ERROR_NONE) ? true : false;

   $decode_image = $image;

But it is not working, Please help me.

  • I thing is JSON function like this - is_JSON($image) – Anas Mansuri Jul 18 '19 at 5:38
  • 1
    @AnasMansuri Is is_JSON work on Magento2?? – temper Jul 18 '19 at 5:50
  • 1
    yes. try with is_JSON() it. – Anas Mansuri Jul 18 '19 at 5:51

By using is_JSON($image) issue solved.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.