pub fn from_json(json: JSONValue, context: &mut Context) -> Self {
        match json {
            JSONValue::Number(v) => {
                if let Some(Ok(integer_32)) = v.as_i64().map(i32::try_from) {
                    Self::new(integer_32)
                } else {
                    Self::new(v.as_f64().expect("Could not convert value to f64"))
                }
            }
            JSONValue::String(v) => Self::new(v),
            JSONValue::Bool(v) => Self::new(v),
            JSONValue::Array(vs) => {
                let vs: Vec<_> = vs
                    .into_iter()
                    .map(|json| Self::from_json(json, context))
                    .collect();

                Array::create_array_from_list(vs, context).into()
            }
            JSONValue::Object(obj) => {
                let new_obj = JsValue::new_object(context);
                for (key, json) in obj.into_iter() {
                    let value = Self::from_json(json, context);
                    new_obj.set_property(
                        key,
                        PropertyDescriptor::builder()
                            .value(value)
                            .writable(true)
                            .enumerable(true)
                            .configurable(true),
                    );
                }
                new_obj
            }
            JSONValue::Null => Self::null(),
        }
    }
/// Convert from a JSON value to a JS value
Convert from a JSON value to a JS value
Convert from a JSON value to a JS value
pub fn from_json(json: JSONValue, context: &mut Context) -> Self {
        match json {
            JSONValue::Number(v) => {
                if let Some(Ok(integer_32)) = v.as_i64().map(i32::try_from) {
                    Self::new(integer_32)
                } else {
                    Self::new(v.as_f64().expect("Could not convert value to f64"))
                }
            }
            JSONValue::String(v) => Self::new(v),
            JSONValue::Bool(v) => Self::new(v),
            JSONValue::Array(vs) => {
                let vs: Vec<_> = vs
                    .into_iter()
                    .map(|json| Self::from_json(json, context))
                    .collect();
                Array::create_array_from_list(vs, context).into()
            }
            JSONValue::Object(obj) => {
                let new_obj = JsValue::new_object(context);
                for (key, json) in obj.into_iter() {
                    let value = Self::from_json(json, context);
                    new_obj.set_property(
                        key,
                        PropertyDescriptor::builder()
                            .value(value)
                            .writable(true)
                            .enumerable(true)
                            .configurable(true),
                    );
                }
                new_obj
            }
            JSONValue::Null => Self::null(),
        }
    }
pub fn from_json ( json : JSONValue , context : & mut Context ) -> Self { match json { JSONValue :: Number ( v ) => { if let Some ( Ok ( integer_32 ) ) = v . as_i64 ( ) . map ( i32 :: try_from ) { Self :: new ( integer_32 ) } else { Self :: new ( v . as_f64 ( ) . expect ( " " ) ) } } JSONValue :: String ( v ) => Self :: new ( v ) , JSONValue :: Bool ( v ) => Self :: new ( v ) , JSONValue :: Array ( vs ) => { let vs : Vec < _ > = vs . into_iter ( ) . map ( | json | Self :: from_json ( json , context ) ) . collect ( ) ; Array :: create_array_from_list ( vs , context ) . into ( ) } JSONValue :: Object ( obj ) => { let new_obj = JsValue :: new_object ( context ) ; for ( key , json ) in obj . into_iter ( ) { let value = Self :: from_json ( json , context ) ; new_obj . set_property ( key , PropertyDescriptor :: builder ( ) . value ( value ) . writable ( true ) . enumerable ( true ) . configurable ( true ) , ) ; } new_obj } JSONValue :: Null => Self :: null ( ) , } }
Convert from a JSON value to a JS value
Convert from a JSON value to a JS value
json
JSONValue
context
&mut Context
json
JSONValue
context
&mut Context