jsonkit 0.1.0

A simple JSON utility library for Rust.
Documentation

🚀 JSON KiT

License: MIT Rust Maintenance

JSON KiT is a high-performance, lightweight Rust utility library engineered for robust JSON data processing.

Its primary mission is to bridge the gap between "JSON with Comments" (JSONC) and standard JSON parsers by efficiently sanitizing input strings. Whether you are dealing with configuration files or human-readable data formats, JSON KiT ensures your data is parse-ready.


📑 Table of Contents


✨ Features

  • 🛡️ Comment Stripping: Seamlessly removes standard C-style comments.
    • Single-line: // comment
    • Multi-line: /* comment */
  • 🧠 Context-Aware Parsing: Intelligently distinguishes between actual comments and comment-like patterns within string literals (e.g., "url": "http://example.com").
  • ⚡ High Performance: Built on top of the regex crate with OnceLock for thread-safe, lazy initialization and optimal execution speed.

📦 Installation

Integrate jsonkit into your project by adding it to your Cargo.toml:

[dependencies]
jsonkit = { git = "https://gitlab.com/lazylib/rs/jsonkit" }

Note: As this crate is hosted in a private/custom repository, please ensure your git configuration allows access if necessary.

🚀 Usage

Sanitizing JSON content is straightforward. Here is a complete example:

use jsonkit::remove_comment;

fn main() {
    // Input: JSON with comments (JSONC)
    let json_with_comments = r#"
    {
        // User profile configuration
        "name": "Alice",
        "age": 30, /* Age verified */
        "website": "http://example.com" // URL preserved
    }
    "#;

    // Process: Remove comments
    let clean_json = remove_comment(json_with_comments);

    // Output: Standard JSON
    println!("{}", clean_json);
}

Output Preview

    {
        
        "name": "Alice",
        "age": 30, 
        "website": "http://example.com" 
    }

📚 API Reference

remove_comment

pub fn remove_comment(json_with_comments: &str) -> String

Transforms a JSON string containing comments into a standard JSON string.

Parameter Type Description
json_with_comments &str The input string containing JSONC data.
Returns String A new, sanitized string ready for parsing.

🛠️ Development

We welcome contributions! To get started with local development:

  1. Clone the repository:

    git clone https://gitlab.com/lazylib/rs/jsonkit.git
    cd jsonkit
    
  2. Run tests: Ensure all functionality works as expected.

    cargo test
    

📄 License

This project is proudly licensed under the MIT License. See the LICENSE file for details.


Made with ❤️ in Rust.