MCPcopy Create free account
hub / github.com/agentforce314/clawcodex / ndjson_safe_dumps

Function ndjson_safe_dumps

src/cli_core/ndjson.py:24–37  ·  view source on GitHub ↗

Serialize ``value`` to a single NDJSON-safe JSON string. Mirrors ``ndjsonSafeStringify`` from the TypeScript implementation.

(value: Any)

Source from the content-addressed store, hash-verified

22
23
24def ndjson_safe_dumps(value: Any) -> str:
25 """Serialize ``value`` to a single NDJSON-safe JSON string.
26
27 Mirrors ``ndjsonSafeStringify`` from the TypeScript implementation.
28 """
29
30 encoded = json.dumps(value, ensure_ascii=False, separators=(",", ":"))
31 if "\u2028" not in encoded and "\u2029" not in encoded:
32 return encoded
33 out_parts: list[str] = []
34 for ch in encoded:
35 replacement = _LINE_SEPARATORS.get(ch)
36 out_parts.append(replacement if replacement is not None else ch)
37 return "".join(out_parts)

Calls 3

joinMethod · 0.80
getMethod · 0.45
appendMethod · 0.45