Add parse_json.
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
use crate::engine::OP_EQUALS;
|
||||
use crate::plugin::*;
|
||||
use crate::{def_package, format_map_as_json, Dynamic, ImmutableString, Map, RhaiResultOf, INT};
|
||||
use crate::{def_package, Dynamic, ImmutableString, Map, NativeCallContext, RhaiResultOf, INT};
|
||||
#[cfg(feature = "no_std")]
|
||||
use std::prelude::v1::*;
|
||||
|
||||
@@ -304,6 +304,9 @@ mod map_functions {
|
||||
/// print(m.to_json()); // prints {"a":1, "b":2, "c":3}
|
||||
/// ```
|
||||
pub fn to_json(map: &mut Map) -> String {
|
||||
format_map_as_json(map)
|
||||
#[cfg(feature = "metadata")]
|
||||
return serde_json::to_string(map).unwrap_or_else(|_| "ERROR".into());
|
||||
#[cfg(not(feature = "metadata"))]
|
||||
return crate::format_map_as_json(map);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user