Skip to main content

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

# 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

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

jmd-0.1.3.tar.gz (8.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

jmd-0.1.3-py3-none-any.whl (8.6 kB view details)

Uploaded Python 3

File details

Details for the file jmd-0.1.3.tar.gz.

File metadata

  • Download URL: jmd-0.1.3.tar.gz
  • Upload date:
  • Size: 8.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for jmd-0.1.3.tar.gz
Algorithm Hash digest
SHA256 d501294c0b3054232c4fc8f32f755a7154542997b3a3ee29d91a9c5b0c75a485
MD5 aa0bf2635796f0afdeb6aa9b5341f369
BLAKE2b-256 fbc723ab14f29b7e96ee9dc4d30acf66e2439d05ff2169f1381933573a136e3c

See more details on using hashes here.

File details

Details for the file jmd-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: jmd-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 8.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for jmd-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 595a068ceed44425f683f088866c28c5654c2b5eb96dc096d29d2f3bc0e4b089
MD5 499a336c8ac4fead9f0fdcfcc196ce83
BLAKE2b-256 66761b2d284d6a3519b9f9ac0e33d758b29599278746c228a9cdaf376dc6bfc2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page