JavaScript object to JSON
As this works for you and as there is no javascript interpreter in PHP unless you install it (there is a V8 PHP extension IIRC), I would say you did this right so far.

Which else criteria could there be than your own ones? You should probably write unit and acceptance tests for it. And remove the var_dump debug cruft out of it. But by the way you do this on it's own, it does not look too far off.