#json #markdown #convert-json #serde #conversion #convert #rust

json2markdown

A Rust library to convert JSON data into well-structured Markdown format

3 unstable releases

0.2.1 Feb 7, 2025
0.2.0 Feb 1, 2025
0.1.0 Jan 20, 2025

#1581 in Parser implementations

Download history 47/week @ 2025-01-14 49/week @ 2025-01-21 104/week @ 2025-01-28 152/week @ 2025-02-04 6/week @ 2025-02-11

358 downloads per month

MIT license

17KB
205 lines

JSON to Markdown Renderer in Rust

Overview

A powerful and flexible Rust library for converting complex JSON structures into beautifully formatted Markdown documents. This library provides a highly customizable renderer that can transform nested JSON objects into clean, hierarchical markdown.

Features

  • 🚀 Supports deeply nested JSON structures
  • 📝 Configurable indentation and rendering styles
  • 🔍 Handles various JSON value types (objects, arrays, strings, numbers, booleans)
  • 🧩 Modular design with easy extensibility

Installation

Add the following to your Cargo.toml:

[dependencies]
json2markdown = "0.2.1"

# use the ``preserve_order`` feature if the ordering is needed
serde_json = "1"

Basic Usage

use serde_json::Value;
use json2markdown::MarkdownRenderer;

fn main() {
    let json = serde_json::from_str(r#"{"title": "My Project"}"#).unwrap();

    let renderer = MarkdownRenderer::default();
    let markdown = renderer.render(&json);

    println!("{markdown}");
}

Customization

Indentation

You can customize indentation by adjusting the parameters:

// 1 space base indentation, 2 spaces for the depth
let renderer = MarkdownRenderer::new(1, 2);

Advanced Example

let complex_json = serde_json::json!({
    "project": {
        "name": "Advanced Project",
        "goals": [
            "Improve efficiency",
            "Reduce manual work"
        ],
        "team": {
            "size": 5,
            "roles": ["Developer", "Designer"]
        }
    }
});

let renderer = MarkdownRenderer::default();
let markdown = renderer.render(&complex_json);

Performance Considerations

  • The renderer is designed to handle large, complex JSON structures
  • Memory usage scales with JSON complexity
  • Recommended for medium to large JSON documents

Contributing

  1. Fork the repository
  2. Create your feature branch
  3. Commit your changes
  4. Push to the branch
  5. Create a new Pull Request

License

MIT

Roadmap

  • Add support for custom markdown formatting
  • Implement more rendering options
  • Create configuration presets
  • Improve performance for very large JSON structures
  • Improve the indentations to suit the style

Dependencies

~4–6MB
~109K SLoC