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

Function parse_input_to_json

lib/dsc-lib/src/util.rs:44–63  ·  view source on GitHub ↗

Return JSON string whether the input is JSON or YAML # Arguments `value` - A string slice that holds the input value # Returns A string that holds the JSON value # Errors This function will return an error if the input value is not valid JSON or YAML

(value: &str)

Source from the content-addressed store, hash-verified

42///
43/// This function will return an error if the input value is not valid JSON or YAML
44pub fn parse_input_to_json(value: &str) -> Result<String, DscError> {
45 match serde_json::from_str(value) {
46 Ok(json) => Ok(json),
47 Err(_) => {
48 match serde_yaml::from_str::<Value>(value) {
49 Ok(yaml) => {
50 match serde_json::to_value(yaml) {
51 Ok(json) => Ok(json.to_string()),
52 Err(err) => {
53 Err(DscError::Json(err))
54 }
55 }
56 },
57 Err(err) => {
58 Err(DscError::Yaml(err))
59 }
60 }
61 }
62 }
63}
64
65/// Converts a wildcard string to a regex pattern.
66///

Callers 2

get_contentsFunction · 0.85
get_inputFunction · 0.85

Calls 2

JsonClass · 0.85
from_strFunction · 0.50

Tested by

no test coverage detected