jom
jom is a lightweight Rust library that converts JSON data into Markdown by replacing placeholders in a Markdown template with corresponding JSON values. It supports nested keys using dot notation (e.g., {user.name}).
Overview
This library provides a single public function, json_to_markdown, which:
- Parses a JSON string.
- Searches for placeholders in a Markdown template.
- Replaces each placeholder with the value from the JSON data if available.
- Leaves the placeholder unchanged if the corresponding key does not exist.
Installation
Add the following to your Cargo.toml:
[]
= "0.1.2"
Usage
Below is a quick example demonstrating how to use the library:
use json_to_markdown;
API Reference
json_to_markdown
-
Parameters:
json_data: A string slice containing valid JSON.markdown: A string slice containing a Markdown template with placeholders in the form{key}or{nested.key}.
-
Returns:
- A
Result<String, serde_json::Error>where theStringis the rendered Markdown if successful, or aserde_json::Errorif JSON parsing fails.
- A
-
Behavior:
- The function replaces every placeholder found in the
markdowntemplate with the corresponding value from the parsed JSON. If a key is not found in the JSON data, the original placeholder is retained.
- The function replaces every placeholder found in the
License
This project is licensed under the MIT License.