|
@ -1,10 +1,11 @@ |
|
|
|
|
|
use serde_json as json; |
|
|
use crate::parser::{parser, Value}; |
|
|
use crate::parser::{parser, Value}; |
|
|
|
|
|
|
|
|
fn json_convert(content: &str) -> Result<String, String> { // convert to JSON format
|
|
|
fn json_convert(content: &str) -> Result<String, String> { // convert to JSON format
|
|
|
let data = match parser(content)? { |
|
|
let data = match parser(content)? { |
|
|
Value::JSON(json) => serde_json::to_string(&json), |
|
|
Value::JSON(_json) => json::to_string(&_json), |
|
|
Value::YAML(yaml) => serde_json::to_string(&yaml), |
|
|
Value::YAML(_yaml) => json::to_string(&_yaml), |
|
|
Value::TOML(toml) => serde_json::to_string(&toml), |
|
|
Value::TOML(_toml) => json::to_string(&_toml), |
|
|
}; |
|
|
}; |
|
|
match data { |
|
|
match data { |
|
|
Ok(data) => Ok(data), |
|
|
Ok(data) => Ok(data), |
|
@ -15,6 +16,6 @@ fn json_convert(content: &str) -> Result<String, String> { // convert to JSON fo |
|
|
pub fn to_json(content: &str) -> Option<String> { // to JSON string
|
|
|
pub fn to_json(content: &str) -> Option<String> { // to JSON string
|
|
|
match json_convert(content) { |
|
|
match json_convert(content) { |
|
|
Ok(data) => Some(data), |
|
|
Ok(data) => Some(data), |
|
|
Err(_) => None, |
|
|
Err(_) => None, // convert failed
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |