Streaming JSON to Markdown converter
Project description
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
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\npython\ndef add(a, b):\n return a + b\n"},
{"role": "user", "content": "Thanks!"},
{"role": "assistant", "content": "You're welcome."}
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!
>
> > role: assistant
> > content:
> > > You're welcome.
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 + brole: user
content: Thanks!role: assistant
content:You're welcome.
Example 2
Initial JSON
{"name": "Gilbert", "wins": [["straight\nwin", "7♣"], {"Test": ["8"]}]}
Converted Markdown
> name: Gilbert
> # wins:
> > > > straight
> > > > win
>
> > > 7♣
>
> > > # Test:
> > > > > 8
Rendered Markdown
name: Gilbert
wins:
straight
win7♣
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
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file jmd-0.1.2.tar.gz.
File metadata
- Download URL: jmd-0.1.2.tar.gz
- Upload date:
- Size: 5.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.25
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
135467d920e322ac2b0991379f1476c1c14555bab3a7c061015d66abd57c75d2
|
|
| MD5 |
cbefe89873caaf1b3cae586783f1f252
|
|
| BLAKE2b-256 |
46d78d3f35205906f1a7a057a1d4fdaa6af1807ea1198f7376c26d2d8846013e
|
File details
Details for the file jmd-0.1.2-py3-none-any.whl.
File metadata
- Download URL: jmd-0.1.2-py3-none-any.whl
- Upload date:
- Size: 6.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.25
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ce9714337a27a3933c96352ed286bc10a18a89e9f2283488f39003dee3c8b0e1
|
|
| MD5 |
4386f29599097b0d8a411a34b4ed1ff4
|
|
| BLAKE2b-256 |
302b7fc888a0600d7d6ca63a7916d6f61aae4dfdc58361812f799d2784331921
|