Skip to content

dlgforge.utils.json

JSON extraction and parsing helpers for model outputs.

strip_code_fences(text)

Strip code fences.

Parameters:

Name Type Description Default
text str

Input text.

required

Returns:

Name Type Description
str str

Value produced by this API.

Raises:

Type Description
Exception

Propagates unexpected runtime errors from downstream calls.

Side Effects / I/O: - Primarily performs in-memory transformations.

Preconditions / Invariants: - Callers should provide arguments matching annotated types and expected data contracts.

Examples:

>>> from dlgforge.utils.json import strip_code_fences
>>> strip_code_fences(...)

extract_json_object(text)

Extract json object.

Parameters:

Name Type Description Default
text str

Input text.

required

Returns:

Type Description
Optional[Dict[str, Any]]

Optional[Dict[str, Any]]: Value produced by this API.

Raises:

Type Description
Exception

Propagates unexpected runtime errors from downstream calls.

Side Effects / I/O: - Primarily performs in-memory transformations.

Preconditions / Invariants: - Callers should provide arguments matching annotated types and expected data contracts.

Examples:

>>> from dlgforge.utils.json import extract_json_object
>>> extract_json_object(...)

parse_json_object(text)

Parse json object.

Parameters:

Name Type Description Default
text str

Input text.

required

Returns:

Type Description
Dict[str, Any]

Dict[str, Any]: Value produced by this API.

Raises:

Type Description
Exception

Propagates unexpected runtime errors from downstream calls.

Side Effects / I/O: - Primarily performs in-memory transformations.

Preconditions / Invariants: - Callers should provide arguments matching annotated types and expected data contracts.

Examples:

>>> from dlgforge.utils.json import parse_json_object
>>> parse_json_object(...)