MCPcopy Create free account
hub / github.com/PowerShell/DSC / parse_input_to_json_value

Function parse_input_to_json_value

dsc/src/util.rs:600–612  ·  view source on GitHub ↗

Parse input string as JSON or YAML and return a serde_json::Value. # Arguments `input` - The input string to parse (JSON or YAML format) `context` - Context string for error messages (e.g., "file parameters", "inline parameters") # Returns `Result ` - Parsed JSON value # Errors This function will return an error if the input cannot be parsed as valid JSON or YAML

(input: &str, context: &str)

Source from the content-addressed store, hash-verified

598///
599/// This function will return an error if the input cannot be parsed as valid JSON or YAML
600fn parse_input_to_json_value(input: &str, context: &str) -> Result<serde_json::Value, DscError> {
601 match serde_json::from_str(input) {
602 Ok(json) => Ok(json),
603 Err(_) => {
604 match serde_yaml::from_str::<serde_yaml::Value>(input) {
605 Ok(yaml) => Ok(serde_json::to_value(yaml)?),
606 Err(err) => {
607 Err(DscError::Parser(t!(&format!("util.failedToParse{context}"), error = err.to_string()).to_string()))
608 }
609 }
610 }
611 }
612}
613
614/// Convert parameter input to a map, handling different formats.
615///

Callers 1

params_to_mapFunction · 0.85

Calls 1

from_strFunction · 0.50

Tested by

no test coverage detected