Skip to main content

add_config_section_field

Function add_config_section_field 

Source
pub fn add_config_section_field(
    config_json: &str,
    section_name: &str,
    field_name: &str,
    field_value: &Value,
) -> Result<(String, usize)>
Expand description

Add a field to all items in a configuration section

§Arguments

  • config_json - Configuration JSON string
  • section_name - Section name
  • field_name - Field name to add
  • field_value - Value for the field

§Returns

Returns (modified_config, item_count) tuple on success

§Example

use sz_configtool_lib::config_sections;
use serde_json::json;

let config = r#"{"G2_CONFIG": {"CFG_ATTR": [{"ATTR_CODE": "NAME"}]}}"#;
let (modified, count) = config_sections::add_config_section_field(
    config,
    "CFG_ATTR",
    "NEW_FIELD",
    &json!("default")
).unwrap();
assert_eq!(count, 1);