yiisoft / json

JSON encoding and decoding
https://www.yiiframework.com/
BSD 3-Clause "New" or "Revised" License
26 stars 8 forks source link

IsJson helper method #6

Closed nadar closed 4 years ago

nadar commented 4 years ago

We have a very convenient method to check whether an input is already a json value:

https://github.com/luyadev/luya/blob/master/core/helpers/Json.php#L19-L49

If this sounds interesting for this package, i would make a PR.

samdark commented 4 years ago

Thanks for idea but I don't think it fits.

  1. Seems it's not checking for valid JSON but is doing something else. It will return false for "test" or 42 that is valid JSON.
  2. If we consider these valid variants, there's no profit in having this method since we'll do decode in order to know if JSON is valid.
  3. We have to catch \JsonException anyway when decoding.
nadar commented 4 years ago

What your are talking about is this i assume: https://stackoverflow.com/a/7487892/4611030

But in 99% percent of the situations the method could help developers when dealing with JSON. So maybe make a good example how people can ensure that behavior with this package with try catch blocks.

nadar commented 4 years ago

(ps: maybe its also just my personal taste of what i expected from such a library: methods which helps me to find solutions for problems right at my fingertips...)

samdark commented 4 years ago

It is likely that I'm not getting the problem and how this helper method solves it.