Added check for toJson method that works like toDict, except that the return value is treated as json that will be merged into the output during encode.