Add to_json and from_json functions