Skip to main content

Module json

Module json 

Source
Expand description

JSON format support for configuration content.

This module provides the JsonContent type for working with JSON configuration files.

§Features

  • Full CRUD operations (select, insert, update, delete, upsert)
  • Pretty-printed output
  • Consistent round-trip serialization

§Example

use bare_config::json::JsonContent;
use bare_config::{ConfigContent, key::Key};
use bare_config::value::Value;
use std::str::FromStr;

// Parse JSON configuration
let config = JsonContent::from_str(r#"{"database": {"url": "localhost"}}"#).unwrap();

// Select a value
let value = config.select(&Key::from_str(".database.url").unwrap()).unwrap();
assert_eq!(value.as_str(), Some("localhost"));

// Insert a new value
let mut config = JsonContent::from_str("{}").unwrap();
config.insert(&Key::from_str(".server.port").unwrap(), &Value::string("8080")).unwrap();

// Format as string (pretty-printed)
let output = config.to_string();
println!("{}", output);

Structs§

JsonContent
JSON configuration content.