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)
| 42 | /// |
| 43 | /// This function will return an error if the input value is not valid JSON or YAML |
| 44 | pub 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 | /// |
no test coverage detected