MCPcopy Index your code
hub / github.com/OpenBMB/ChatDev / _parse_json_dict

Function _parse_json_dict

server/services/batch_parser.py:147–178  ·  view source on GitHub ↗
(
    row: Dict[str, Any],
    column: Optional[str],
    row_index: int,
)

Source from the content-addressed store, hash-verified

145
146
147def _parse_json_dict(
148 row: Dict[str, Any],
149 column: Optional[str],
150 row_index: int,
151) -> Dict[str, Any]:
152 if not column:
153 return {}
154 raw_value = row.get(column)
155 if raw_value is None or (isinstance(raw_value, float) and pd.isna(raw_value)):
156 return {}
157 if isinstance(raw_value, dict):
158 return raw_value
159 if isinstance(raw_value, str):
160 if not raw_value.strip():
161 return {}
162 try:
163 parsed = json.loads(raw_value)
164 except json.JSONDecodeError as exc:
165 raise ValidationError(
166 f"Invalid JSON in Vars: {exc}",
167 details={"row_index": row_index},
168 )
169 if not isinstance(parsed, dict):
170 raise ValidationError(
171 "Vars must be a JSON object",
172 details={"row_index": row_index},
173 )
174 return parsed
175 raise ValidationError(
176 "Vars must be a JSON object",
177 details={"row_index": row_index},
178 )
179
180
181def _ensure_string_list(value: Any, row_index: int, field: str) -> List[str]:

Callers 1

_parse_dataframeFunction · 0.85

Calls 2

ValidationErrorClass · 0.90
getMethod · 0.45

Tested by

no test coverage detected