finish up 'toJSON'; migrate some other JSON parsing code