jmd - JSON to Markdown
Streaming JSON to Markdown converter using blockquote syntax.
Installation
pip install jmd
Usage
# Pipe JSON
cat data.json | jmd
# From file
jmd data.json
# JSONL
cat records.jsonl | jmd
# With head (streaming)
cat huge.json | jmd | head -20
# With key filtering
jq '.items[]' data.json | jmd
# Output to HTML, for viewing in browser
jmd data.json --html > data.html
chromium data.html
Examples
Example 1
Initial JSON
[{"role": "user", "content": "Can you write a python function to add two numbers?"},
{"role": "assistant", "content": "Sure! Here it is:\n\n```python\ndef add(a, b):\n return a + b```\n"},
{"role": "user", "content": "Thanks! And some Latex?"},
{"role": "assistant", "content": "Sure. Here is an equation: $a+b$\n\nAnd a display block:\n$$\n\\int_0^\\infty x^2 dx\n$$"}]
Rendered Markdown
role: user
content: Can you write a python function to add two numbers?role: assistant
content:Sure! Here it is:
def add(a, b): return a + b```role: user
content: Thanks! And some Latex?role: assistant
content:Sure. Here is an equation: $a+b$
And a display block:
$$
\int_0^\infty x^2 dx
$$
Converted Markdown
> > role: user
> > content: Can you write a python function to add two numbers?
>
> > role: assistant
> > content:
> > > Sure! Here it is:
> > >
> > > ```python
> > > def add(a, b):
> > > return a + b```
> > >
>
> > role: user
> > content: Thanks! And some Latex?
>
> > role: assistant
> > content:
> > > Sure. Here is an equation: $a+b$
> > >
> > > And a display block:
> > > $$
> > > \int_0^\infty x^2 dx
> > > $$
Example 2
Initial JSON
{"name": "Gilbert", "wins": [["straight\nwin", "7♣"], {"Test": ["8"]}]}
Rendered Markdown
name: Gilbert
wins:
straight
win7♣
Test:
8
Converted Markdown
> name: Gilbert
> # wins:
> > > > straight
> > > > win
>
> > > 7♣
>
> > > # Test:
> > > > > 8
Python API
from jmd import to_markdown, to_markdown_from_str, stream_json_to_md
# From Python object
md = to_markdown({"name": "Alice", "items": [1, 2, 3]})
# From JSON string
md = to_markdown_from_str('{"key": "value"}')
# Streaming from file
with open("data.json") as f:
for line in stream_json_to_md(f):
print(line)
Format
Unstable, subject to change.
| JSON | Markdown |
|---|---|
{"key": "value"} |
> key: value |
{"key": "has: colon"} |
> key: + > > has: colon |
{"# list": [...]} |
> # list: + items |
{"bad key": v} |
> <q>bad key</q>: v |
[], {}, "" |
[], {}, "" (inline) |
| Array items | Separated by > |
| Multiline strings | depth+1, no separator |
Features
- Streaming: O(chunk + max_string + depth) memory
- C-accelerated: Uses
json.decoder.scanstring - JSONL support: Multiple JSON values
- Pipe-friendly: Handles
| headgracefully
Metadata
Release files for jmd 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| jmd-0.1.3.tar.gz | 8.8 kB | Without provenance | Details for jmd-0.1.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| jmd-0.1.3-py3-none-any.whl | Python 3 | none | any | Details for jmd-0.1.3-py3-none-any.whl |
Total release size: 17.4 kB
Release files / jmd-0.1.3.tar.gz
| Download URL | jmd-0.1.3.tar.gz |
|---|---|
| Size | 8.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d501294c0b3054232c4fc8f32f755a7154542997b3a3ee29d91a9c5b0c75a485
|
|
BLAKE2b-256 checksum How to use checksums |
fbc723ab14f29b7e96ee9dc4d30acf66e2439d05ff2169f1381933573a136e3c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.25
|
Release files / jmd-0.1.3-py3-none-any.whl
| Download URL | jmd-0.1.3-py3-none-any.whl |
|---|---|
| Size | 8.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
595a068ceed44425f683f088866c28c5654c2b5eb96dc096d29d2f3bc0e4b089
|
|
BLAKE2b-256 checksum How to use checksums |
66761b2d284d6a3519b9f9ac0e33d758b29599278746c228a9cdaf376dc6bfc2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.25
|
Security for jmd 0.1.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.