Don't convert the tree to JSON before checking it.  Just check it directly.