Reduce code mass of as_json method