| Crates.io | jom |
| lib.rs | jom |
| version | 0.1.4 |
| created_at | 2025-02-08 21:42:01.403241+00 |
| updated_at | 2025-02-22 22:46:15.069929+00 |
| description | A crate to convert JSON data to markdown by replacing placeholders with JSON values. |
| homepage | |
| repository | https://github.com/ZiyadBoshima/jom |
| max_upload_size | |
| id | 1548427 |
| size | 14,382 |
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}) and now includes special syntax to easily render arrays and objects as Markdown list items.
This library provides a single public function, json_to_markdown, which:
{user.name})....{key} syntax, which renders array elements as list items (using - ) and object key/value pairs as list items in key: value format.Add the following to your Cargo.toml:
[dependencies]
jom = "<version>"
Below is a quick example demonstrating how to use the library with both standard placeholders and the new array/object destructuring syntax:
use jom::json_to_markdown;
fn main() -> serde_json::Result<()> {
let json_data = r#"
{
"name": "John Doe",
"age": 43,
"contact": ["+44 1234567", "+44 2345678"],
"skills": {
"languages": ["Rust", "Python", "JavaScript"],
"tools": ["Git", "Docker", "Kubernetes"]
}
}
"#;
let markdown_template = r#"
# {name}
## {age}
### Contact Details
...{contact}
### Skills
#### Languages
...{skills.languages}
#### Tools
...{skills.tools}
"#;
let rendered = json_to_markdown(json_data, markdown_template)?;
println!("{}", rendered);
Ok(())
}
In the example above:
{name} and {age} are replaced directly....{contact} placeholder detects that contact is an array and converts each element into a Markdown list item....{skills.languages} and ...{skills.tools} render their respective arrays as lists.json_to_markdownpub fn json_to_markdown(json_data: &str, markdown: &str) -> serde_json::Result<String>
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}. For array or object destructuring, use the syntax ...{key}.Returns:
Result<String, serde_json::Error> where the String is the rendered Markdown if successful, or a serde_json::Error if JSON parsing fails.Behavior:
..., the function checks if the JSON value is an array or an object and renders each element as a Markdown list item.This project was inspired by vvhg1's fractalparser 🐍.
This project is licensed under the MIT License.