Skip to content

Commit

Permalink
python/file_formats: Document JSON compact format
Browse files Browse the repository at this point in the history
  • Loading branch information
jpmckinney committed Jun 14, 2023
1 parent 4161ec8 commit 17f6b47
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions docs/python/file_formats.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,20 @@ For *large files*, use the `same techniques <https://ocdskit.readthedocs.io/en/l
Output
~~~~~~

Indent with 2 spaces, use UTF-8 characters, and preserve order of object pairs. Example:
Indent with 2 spaces and use UTF-8 characters. Example:

.. code-block:: python
with open(path, 'w') as f:
with open(path, "w") as f:
json.dump(data, f, ensure_ascii=False, indent=2)
f.write('\n')
f.write("\n")
Or, in a compact format:

.. code-block:: python
with open(path, "w") as f:
json.dump(data, f, separators=(",", ":"))
CSV
---
Expand All @@ -59,7 +66,7 @@ Use LF (``\n``) as the line terminator. Example:

.. code-block:: python
with open(path, 'w') as f:
writer = csv.DictWriter(f, fieldnames, lineterminator='\n')
with open(path, "w") as f:
writer = csv.DictWriter(f, fieldnames, lineterminator="\n")
writer.writeheader()
writer.writerows(rows)

0 comments on commit 17f6b47

Please sign in to comment.