topmark.core.machine.serializers¶
topmark / core / machine / serializers
Pure JSON/NDJSON serialization utilities for machine-readable output.
This module converts already-shaped machine-readable output objects (envelopes or NDJSON record mappings) into strings.
It is intentionally:
- Console-free (no ConsoleLike, no printing)
- Click-free
- side-effect-free (serialization only)
Separation of concerns:
- topmark.core.machine.payloads builds payload objects
(domain data, no envelope).
- topmark.core.machine.envelopes builds envelopes/records
(adds meta/kind/container keys).
- This module serializes those shapes to JSON/NDJSON strings.
Conventions:
- json.dumps() does not append a trailing newline.
- serialize_ndjson() returns a string that does end with a final \\n,
which is convenient for CLI printing and piping.
serialize_json_object ¶
Serialize an object to pretty-printed JSON (no trailing newline).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
object
|
The object to serialize. |
required |
Returns:
| Type | Description |
|---|---|
str
|
A pretty-printed JSON string (no trailing newline). |
Source code in src/topmark/core/machine/serializers.py
serialize_json_envelope ¶
Serialize a JSON envelope with meta plus named payloads.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
meta
|
MetaPayload
|
Metadata payload (tool/version). |
required |
**payloads
|
object
|
Named payload objects. Each value may be a dict-like object or
an object exposing |
{}
|
Returns:
| Type | Description |
|---|---|
str
|
Pretty-printed JSON string (no trailing newline). |
Source code in src/topmark/core/machine/serializers.py
iter_ndjson_strings ¶
Serialize shaped NDJSON records into per-line JSON strings.
Each record mapping must already include its envelope (typically "kind" and "meta").
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
records
|
Iterator[Mapping[str, object]]
|
Iterator of shaped NDJSON record mappings. |
required |
Yields:
| Type | Description |
|---|---|
str
|
One JSON string per record (no trailing newline). |
Source code in src/topmark/core/machine/serializers.py
serialize_ndjson ¶
Serialize NDJSON record mappings into a newline-delimited string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
records
|
Iterator[Mapping[str, object]]
|
Iterator of shaped NDJSON record mappings. |
required |
Returns:
| Type | Description |
|---|---|
str
|
A string containing one JSON object per line, ending with a trailing newline. |