pub fn edn_to_json(data: Edn, add_colon: bool) -> Result<Value, String> {
  match data {
    Edn::Nil => Ok(Value::Null),
    Edn::Bool(b) => Ok(Value::Bool(b)),
    Edn::Number(n) => match serde_json::value::Number::from_f64(n) {
      Some(v) => Ok(Value::Number(v)),
      None => Err(format!("failed to convert to number: {}", n)),
    },
    Edn::Symbol(s, ..) => Ok(Value::String((*s).to_string())),
    Edn::Keyword(s) => {
      if add_colon {
        Ok(Value::String(format!(":{}", s.to_owned())))
      } else {
        Ok(Value::String((*s.to_str()).to_string()))
      }
    }
    Edn::Str(s) => Ok(Value::String((*s).to_string())),
    Edn::List(xs) => {
      let mut ys: Vec<Value> = vec![];
      for x in xs {
        ys.push(edn_to_json(x, add_colon)?);
      }
      Ok(Value::Array(ys))
    }
    Edn::Map(xs) => {
      let mut data = serde_json::Map::new();
      for (k, v) in xs {
        match k {
          Edn::Str(s) => {
            data.insert(s.to_string(), edn_to_json(v, add_colon)?);
          }
          Edn::Keyword(s) => {
            if add_colon {
              data.insert(format!(":{}", s.to_owned()), edn_to_json(v, add_colon)?);
            } else {
              data.insert(s.to_string(), edn_to_json(v, add_colon)?);
            }
          }
          a => return Err(format!("expected string/keyword for json keys, got: {}", a)),
        }
      }

      Ok(Value::Object(data))
    }
    Edn::Record(_, entries) => {
      let mut data = serde_json::Map::new();
      for entry in entries {
        data.insert(
          entry.0.to_string(),
          edn_to_json(entry.1.to_owned(), add_colon)?,
        );
      }
      Ok(Value::Object(data))
    }
    a => Err(format!("cannot convert to json: {}", a)),
  }
}
/// option for "add colon to keyword"
option for "add colon to keyword"
option for " add colon to keyword "
pub fn edn_to_json(data: Edn, add_colon: bool) -> Result<Value, String> {
  match data {
    Edn::Nil => Ok(Value::Null),
    Edn::Bool(b) => Ok(Value::Bool(b)),
    Edn::Number(n) => match serde_json::value::Number::from_f64(n) {
      Some(v) => Ok(Value::Number(v)),
      None => Err(format!("failed to convert to number: {}", n)),
    },
    Edn::Symbol(s, ..) => Ok(Value::String((*s).to_string())),
    Edn::Keyword(s) => {
      if add_colon {
        Ok(Value::String(format!(":{}", s.to_owned())))
      } else {
        Ok(Value::String((*s.to_str()).to_string()))
      }
    }
    Edn::Str(s) => Ok(Value::String((*s).to_string())),
    Edn::List(xs) => {
      let mut ys: Vec<Value> = vec![];
      for x in xs {
        ys.push(edn_to_json(x, add_colon)?);
      }
      Ok(Value::Array(ys))
    }
    Edn::Map(xs) => {
      let mut data = serde_json::Map::new();
      for (k, v) in xs {
        match k {
          Edn::Str(s) => {
            data.insert(s.to_string(), edn_to_json(v, add_colon)?);
          }
          Edn::Keyword(s) => {
            if add_colon {
              data.insert(format!(":{}", s.to_owned()), edn_to_json(v, add_colon)?);
            } else {
              data.insert(s.to_string(), edn_to_json(v, add_colon)?);
            }
          }
          a => return Err(format!("expected string/keyword for json keys, got: {}", a)),
        }
      }
      Ok(Value::Object(data))
    }
    Edn::Record(_, entries) => {
      let mut data = serde_json::Map::new();
      for entry in entries {
        data.insert(
          entry.0.to_string(),
          edn_to_json(entry.1.to_owned(), add_colon)?,
        );
      }
      Ok(Value::Object(data))
    }
    a => Err(format!("cannot convert to json: {}", a)),
  }
}
pub fn edn_to_json ( data : Edn , add_colon : bool ) -> Result < Value , String > { match data { Edn :: Nil => Ok ( Value :: Null ) , Edn :: Bool ( b ) => Ok ( Value :: Bool ( b ) ) , Edn :: Number ( n ) => match serde_json :: value :: Number :: from_f64 ( n ) { Some ( v ) => Ok ( Value :: Number ( v ) ) , None => Err ( format ! ( " " n ) ) , } , Edn :: Symbol ( s , .. ) => Ok ( Value :: String ( ( * s ) . to_string ( ) ) ) , Edn :: Keyword ( s ) => { if add_colon { Ok ( Value :: String ( format ! ( " " s to_owned ( ) ) ) ) } else { Ok ( Value :: String ( ( * s . to_str ( ) ) . to_string ( ) ) ) } } Edn :: Str ( s ) => Ok ( Value :: String ( ( * s ) . to_string ( ) ) ) , Edn :: List ( xs ) => { let mut ys : Vec < Value > = vec ! [ ] ; for x in xs { ys . push ( edn_to_json ( x , add_colon ) ? ) ; } Ok ( Value :: Array ( ys ) ) } Edn :: Map ( xs ) => { let mut data = serde_json :: Map :: new ( ) ; for ( k , v ) in xs { match k { Edn :: Str ( s ) => { data . insert ( s . to_string ( ) , edn_to_json ( v , add_colon ) ? ) ; } Edn :: Keyword ( s ) => { if add_colon { data . insert ( format ! ( " " s to_owned ( ) ) , edn_to_json ( v , add_colon ) ? ) ; } else { data . insert ( s . to_string ( ) , edn_to_json ( v , add_colon ) ? ) ; } } a => return Err ( format ! ( " " a ) ) , } } Ok ( Value :: Object ( data ) ) } Edn :: Record ( _ , entries ) => { let mut data = serde_json :: Map :: new ( ) ; for entry in entries { data . insert ( entry . 0 . to_string ( ) , edn_to_json ( entry . 1 . to_owned ( ) , add_colon ) ? , ) ; } Ok ( Value :: Object ( data ) ) } a => Err ( format ! ( " " a ) ) , } }
option for "add colon to keyword"
option for " add colon to keyword "
data
Edn
add_colon
bool