fn csv_value_to_json(header: &str, value: &str) -> (String, Value) {
  lazy_static! {
    static ref FIND_NESTING_DELIMITERS: Regex = Regex::new(r"\[\]|\.").unwrap();
  }

  let val: Value = match FIND_NESTING_DELIMITERS.find(header) {
    Some(matching_delimiter) => {
      // get the string following the "[]" delimiter. If empty string, then we know that the value is an array of strings
      let rest_header: &str = &header[matching_delimiter.end()..];

      match matching_delimiter.as_str() {
        // is array
        "[]" => {
          let nested_val = match rest_header {
            // an array of strings
            "" => Value::Array(vec![Value::String(value.to_string())]),
            // an array of object|arrays
            _ => {
              let (_, recursive_val) = csv_value_to_json(rest_header, value);
              Value::Array(vec![recursive_val])
            }
          };

          nested_val
        }

        // is object
        "." => {
          let nested_val = match rest_header {
            // This should never happen. There should always be a non-empty string following the `.`
            "" => panic!("There should always be text following the period (.)"),
            // an object of strings|objects|arrays
            _ => {
              let (recursive_key, recursive_val) = csv_value_to_json(rest_header, value);
              let mut fields = Map::new();
              fields.insert(recursive_key, recursive_val);
              Value::Object(fields)
            }
          };

          nested_val
        }
        _ => panic!("csv_value_to_json() matched a character that should not have been matched."),
      }
    }
    None => Value::String(value.to_string()),
  };

  let root_header_name: Vec<&str> = FIND_NESTING_DELIMITERS.split(header).collect();

  (root_header_name[0].to_string(), val)
}
// Converts the supplied header column string (which describes the json schema) and value into a JSON object.
Converts the supplied header column string (which describes the json schema) and value into a JSON object.
Converts the supplied header column string ( which describes the json schema ) and value into a JSON object .
fn csv_value_to_json(header: &str, value: &str) -> (String, Value) {
  lazy_static! {
    static ref FIND_NESTING_DELIMITERS: Regex = Regex::new(r"\[\]|\.").unwrap();
  }
  let val: Value = match FIND_NESTING_DELIMITERS.find(header) {
    Some(matching_delimiter) => {
      // get the string following the "[]" delimiter. If empty string, then we know that the value is an array of strings
      let rest_header: &str = &header[matching_delimiter.end()..];
      match matching_delimiter.as_str() {
        // is array
        "[]" => {
          let nested_val = match rest_header {
            // an array of strings
            "" => Value::Array(vec![Value::String(value.to_string())]),
            // an array of object|arrays
            _ => {
              let (_, recursive_val) = csv_value_to_json(rest_header, value);
              Value::Array(vec![recursive_val])
            }
          };
          nested_val
        }
        // is object
        "." => {
          let nested_val = match rest_header {
            // This should never happen. There should always be a non-empty string following the `.`
            "" => panic!("There should always be text following the period (.)"),
            // an object of strings|objects|arrays
            _ => {
              let (recursive_key, recursive_val) = csv_value_to_json(rest_header, value);
              let mut fields = Map::new();
              fields.insert(recursive_key, recursive_val);
              Value::Object(fields)
            }
          };
          nested_val
        }
        _ => panic!("csv_value_to_json() matched a character that should not have been matched."),
      }
    }
    None => Value::String(value.to_string()),
  };
  let root_header_name: Vec<&str> = FIND_NESTING_DELIMITERS.split(header).collect();
  (root_header_name[0].to_string(), val)
}
fn csv_value_to_json ( header : & str , value : & str ) -> ( String , Value ) { lazy_static ! { static ref FIND_NESTING_DELIMITERS Regex Regex new ( r"\[\]|\." ) unwrap ( ) } let val : Value = match FIND_NESTING_DELIMITERS . find ( header ) { Some ( matching_delimiter ) => { // get the string following the "[]" delimiter. If empty string, then we know that the value is an array of strings let rest_header : & str = & header [ matching_delimiter . end ( ) .. ] ; match matching_delimiter . as_str ( ) { // is array " " => { let nested_val = match rest_header { // an array of strings " " => Value :: Array ( vec ! [ Value String ( value to_string ( ) ) ] ) , // an array of object|arrays _ => { let ( _ , recursive_val ) = csv_value_to_json ( rest_header , value ) ; Value :: Array ( vec ! [ recursive_val ] ) } } ; nested_val } // is object " " => { let nested_val = match rest_header { // This should never happen. There should always be a non-empty string following the `.` " " => panic ! ( " " ) , // an object of strings|objects|arrays _ => { let ( recursive_key , recursive_val ) = csv_value_to_json ( rest_header , value ) ; let mut fields = Map :: new ( ) ; fields . insert ( recursive_key , recursive_val ) ; Value :: Object ( fields ) } } ; nested_val } _ => panic ! ( " " ) , } } None => Value :: String ( value . to_string ( ) ) , } ; let root_header_name : Vec < & str > = FIND_NESTING_DELIMITERS . split ( header ) . collect ( ) ; ( root_header_name [ 0 ] . to_string ( ) , val ) }
Converts the supplied header column string (which describes the json schema) and value into a JSON object.
Converts the supplied header column string ( which describes the json schema ) and value into a JSON object .
header
&str
value
&str
header
&str
value
&str