0

How would you prevent empty json objects from validating in php such as {} and {"":""}?

3
  • 2
    Why? Validating where, when running json_decode() on them? Commented Oct 20, 2011 at 21:27
  • 3
    You can't prevent it, cause it's valid ... what are you trying to achieve? Commented Oct 20, 2011 at 21:28
  • 1
    empty()? Commented Oct 20, 2011 at 21:29

1 Answer 1

1

One way would be to iterate over the object's properties. Stop as soon as you encounter one with a non-empty name. If you iterate over "everything" and don't come across one such, then the object is "empty".

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.