Skip to main content

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
win

7♣

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 | head gracefully

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)

Source distribution for jmd 0.1.3
File Size Uploaded
jmd-0.1.3.tar.gz 8.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for jmd 0.1.3
File Interpreter ABI Platform
jmd-0.1.3-py3-none-any.whl Python 3 none any Details

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

Release history Release notifications | RSS feed

This release

0.1.3 This release

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page