fn lua_value_to_json(lua_value: rlua::Value) -> serde_json::Value {
    match lua_value {
        rlua::Value::Nil => JValue::Null,
        rlua::Value::Boolean(v) => JValue::Bool(v),
        rlua::Value::Integer(v) => From::from(v as i64),
        rlua::Value::Number(v) => From::from(v as f64),
        rlua::Value::String(v) => From::from(v.to_str().unwrap_or("").to_string()),
        rlua::Value::Table(t) => {
            let is_array = match t.raw_get::<usize, rlua::Value>(1) {
                Ok(rlua::Value::Nil) => false,
                Err(_) => false,
                _ => true,
            };
            if is_array {
                // this table has a sequence part. handle it as an array.
                let v = t
                    .sequence_values::<rlua::Value>()
                    .filter_map(|res| res.ok())
                    .map(|e| lua_value_to_json(e))
                    .collect::<Vec<_>>();
                JValue::Array(v)
            } else {
                // It is an object.
                let hm = serde_json::map::Map::from_iter(
                    t.pairs::<String, rlua::Value>()
                        .filter_map(|res| res.ok())
                        .map(|(k, v)| (k, lua_value_to_json(v))),
                );
                JValue::Object(hm)
            }
        },
        _ => JValue::Null,
    }
}
/// Recursively transform a rlua::Value to a serde_json::Value
Recursively transform a rlua::Value to a serde_json::Value
Recursively transform a rlua :: Value to a serde_json :: Value
fn lua_value_to_json(lua_value: rlua::Value) -> serde_json::Value {
    match lua_value {
        rlua::Value::Nil => JValue::Null,
        rlua::Value::Boolean(v) => JValue::Bool(v),
        rlua::Value::Integer(v) => From::from(v as i64),
        rlua::Value::Number(v) => From::from(v as f64),
        rlua::Value::String(v) => From::from(v.to_str().unwrap_or("").to_string()),
        rlua::Value::Table(t) => {
            let is_array = match t.raw_get::<usize, rlua::Value>(1) {
                Ok(rlua::Value::Nil) => false,
                Err(_) => false,
                _ => true,
            };
            if is_array {
                // this table has a sequence part. handle it as an array.
                let v = t
                    .sequence_values::<rlua::Value>()
                    .filter_map(|res| res.ok())
                    .map(|e| lua_value_to_json(e))
                    .collect::<Vec<_>>();
                JValue::Array(v)
            } else {
                // It is an object.
                let hm = serde_json::map::Map::from_iter(
                    t.pairs::<String, rlua::Value>()
                        .filter_map(|res| res.ok())
                        .map(|(k, v)| (k, lua_value_to_json(v))),
                );
                JValue::Object(hm)
            }
        },
        _ => JValue::Null,
    }
}
fn lua_value_to_json ( lua_value : rlua :: Value ) -> serde_json :: Value { match lua_value { rlua :: Value :: Nil => JValue :: Null , rlua :: Value :: Boolean ( v ) => JValue :: Bool ( v ) , rlua :: Value :: Integer ( v ) => From :: from ( v as i64 ) , rlua :: Value :: Number ( v ) => From :: from ( v as f64 ) , rlua :: Value :: String ( v ) => From :: from ( v . to_str ( ) . unwrap_or ( " " ) . to_string ( ) ) , rlua :: Value :: Table ( t ) => { let is_array = match t . raw_get :: < usize , rlua :: Value > ( 1 ) { Ok ( rlua :: Value :: Nil ) => false , Err ( _ ) => false , _ => true , } ; if is_array { // this table has a sequence part. handle it as an array. let v = t . sequence_values :: < rlua :: Value > ( ) . filter_map ( | res | res . ok ( ) ) . map ( | e | lua_value_to_json ( e ) ) . collect :: < Vec < _ > > ( ) ; JValue :: Array ( v ) } else { // It is an object. let hm = serde_json :: map :: Map :: from_iter ( t . pairs :: < String , rlua :: Value > ( ) . filter_map ( | res | res . ok ( ) ) . map ( | ( k , v ) | ( k , lua_value_to_json ( v ) ) ) , ) ; JValue :: Object ( hm ) } } , _ => JValue :: Null , } }
Recursively transform a rlua::Value to a serde_json::Value
Recursively transform a rlua :: Value to a serde_json :: Value
lua_value
rlua::Value