Use to_json instead of nested javascript construction