ZObject.php and all its inheriting classes (all classes in the ZObjects directory) have a getSerialized() method that transforms a tree of ZObject instances into the JSON representation of that ZObject in canonical or normal form.
Tests for all ZObject classes should be added to check that the instances are serialized properly.
Current code: https://gerrit.wikimedia.org/r/plugins/gitiles/mediawiki/extensions/WikiLambda/+/refs/heads/master/includes/ZObjects/ZObject.php#243 plus that method in sub-classes where over-ridden.
Current coverage report example: https://doc.wikimedia.org/cover-extensions/WikiLambda/includes/ZObjects/ZString.php.html#64