Source code for pytablewriter.writer.text._jsonlines

from typing import Any

from ._json import JsonTableWriter

    import simplejson as json
except ImportError:
    import json  # type: ignore

[docs] class JsonLinesTableWriter(JsonTableWriter): """ A table writer class for JSON lines format. :Example: :ref:`example-jsonl-writer` """ FORMAT_NAME = "json_lines" @property def format_name(self) -> str: return self.FORMAT_NAME @property def support_split_write(self) -> bool: return True
[docs] def write_table(self, **kwargs: Any) -> None: """ |write_table| with `Line-delimited JSON(LDJSON) <>`__ /NDJSON/JSON Lines format. Args: sort_keys (Optional[bool]): If |True|, the output of dictionaries will be sorted by key. Defaults to |False|. Example: :ref:`example-jsonl-writer` """ sort_keys = kwargs.get("sort_keys", False) with self._logger: self._verify_property() self._preprocess() for values in self._table_value_matrix: self._write_line(json.dumps(values, ensure_ascii=False, sort_keys=sort_keys))