animedex.render.json_renderer

JSON renderer with optional source attribution.

When render_json() is called with include_source=True (the default), the resulting JSON carries a top-level _meta block and preserves the source field from the model. Setting include_source=False returns the model’s clean pydantic.BaseModel.model_dump() form: per-field source keys remain (they are part of the schema), but no _meta is injected.

render_json

animedex.render.json_renderer.render_json(model: AnimedexModel, *, include_source: bool = True) str[source]

Render a model to a JSON string.

The function emits the same field-level shape pydantic would produce via AnimedexModel.model_dump_json(); when include_source is true it additionally injects a top-level _meta block that names the upstream(s) consulted, derived from the source field on the model. The block lets a CLI consumer answer “where did this row come from” without inspecting every field.

Parameters:
  • model (AnimedexModel) – The AnimedexModel instance to render.

  • include_source (bool) – When True (default), include the _meta.sources_consulted block. When False, omit it (this matches the --source-attribution=off flag).

Returns:

A JSON-encoded string.

Return type:

str

selftest

animedex.render.json_renderer.selftest() bool[source]

Smoke-test the JSON renderer.

Round-trips a representative anime model through both include_source flavours and verifies the resulting payload decodes and carries the expected keys.

Returns:

True on success.

Return type:

bool