fn flatten_json(
    depth_budget: usize,
    args: &mut RequestField,
    prefix: &mut Vec<String>,
    value: Value,
) -> Result<(), ()> {
    if depth_budget == 0 {
        return Err(());
    }
    match value {
        Value::Array(array) => {
            prefix.push(String::new());
            let idx = prefix.len() - 1;
            for (i, v) in array.into_iter().enumerate() {
                prefix[idx] = format!("{}", i);
                flatten_json(depth_budget - 1, args, prefix, v)?;
            }
            prefix.pop();
        }
        Value::Object(mp) => {
            prefix.push(String::new());
            let idx = prefix.len() - 1;
            for (k, v) in mp.into_iter() {
                prefix[idx] = k;
                flatten_json(depth_budget - 1, args, prefix, v)?;
            }
            prefix.pop();
        }
        Value::String(str) => {
            args.add(json_path(prefix), DataSource::FromBody, str);
        }
        Value::Bool(b) => {
            args.add(
                json_path(prefix),
                DataSource::FromBody,
                (if b { "true" } else { "false" }).to_string(),
            );
        }
        Value::Number(n) => {
            args.add(json_path(prefix), DataSource::FromBody, format!("{}", n));
        }
        Value::Null => {
            args.add(json_path(prefix), DataSource::FromBody, "null".to_string());
        }
    }
    Ok(())
}
/// flatten a JSON tree into the RequestField key/value store
/// key values are build by joining all path names with "_", where path names are:
///   * keys for objects ;
///   * indices for lists.
///
/// Scalar values are converted to string, with lowercase booleans and null values.
flatten a JSON tree into the RequestField key/value store
key values are build by joining all path names with "_", where path names are:
keys for objects ;
indices for lists.

Scalar values are converted to string, with lowercase booleans and null values.
flatten a JSON tree into the RequestField key / value store key values are build by joining all path names with " _ " where path names are : keys for objects ; indices for lists . Scalar values are converted to string with lowercase booleans and null values .
fn flatten_json(
    depth_budget: usize,
    args: &mut RequestField,
    prefix: &mut Vec<String>,
    value: Value,
) -> Result<(), ()> {
    if depth_budget == 0 {
        return Err(());
    }
    match value {
        Value::Array(array) => {
            prefix.push(String::new());
            let idx = prefix.len() - 1;
            for (i, v) in array.into_iter().enumerate() {
                prefix[idx] = format!("{}", i);
                flatten_json(depth_budget - 1, args, prefix, v)?;
            }
            prefix.pop();
        }
        Value::Object(mp) => {
            prefix.push(String::new());
            let idx = prefix.len() - 1;
            for (k, v) in mp.into_iter() {
                prefix[idx] = k;
                flatten_json(depth_budget - 1, args, prefix, v)?;
            }
            prefix.pop();
        }
        Value::String(str) => {
            args.add(json_path(prefix), DataSource::FromBody, str);
        }
        Value::Bool(b) => {
            args.add(
                json_path(prefix),
                DataSource::FromBody,
                (if b { "true" } else { "false" }).to_string(),
            );
        }
        Value::Number(n) => {
            args.add(json_path(prefix), DataSource::FromBody, format!("{}", n));
        }
        Value::Null => {
            args.add(json_path(prefix), DataSource::FromBody, "null".to_string());
        }
    }
    Ok(())
}
fn flatten_json ( depth_budget : usize , args : & mut RequestField , prefix : & mut Vec < String > , value : Value , ) -> Result < ( ) , ( ) > { if depth_budget == 0 { return Err ( ( ) ) ; } match value { Value :: Array ( array ) => { prefix . push ( String :: new ( ) ) ; let idx = prefix . len ( ) - 1 ; for ( i , v ) in array . into_iter ( ) . enumerate ( ) { prefix [ idx ] = format ! ( " " i ) ; flatten_json ( depth_budget - 1 , args , prefix , v ) ? ; } prefix . pop ( ) ; } Value :: Object ( mp ) => { prefix . push ( String :: new ( ) ) ; let idx = prefix . len ( ) - 1 ; for ( k , v ) in mp . into_iter ( ) { prefix [ idx ] = k ; flatten_json ( depth_budget - 1 , args , prefix , v ) ? ; } prefix . pop ( ) ; } Value :: String ( str ) => { args . add ( json_path ( prefix ) , DataSource :: FromBody , str ) ; } Value :: Bool ( b ) => { args . add ( json_path ( prefix ) , DataSource :: FromBody , ( if b { " " } else { " " } ) . to_string ( ) , ) ; } Value :: Number ( n ) => { args . add ( json_path ( prefix ) , DataSource :: FromBody , format ! ( " " n ) ) ; } Value :: Null => { args . add ( json_path ( prefix ) , DataSource :: FromBody , " " . to_string ( ) ) ; } } Ok ( ( ) ) }
flatten a JSON tree into the RequestField key/value store
key values are build by joining all path names with "_", where path names are:
 keys for objects ;
 indices for lists.
flatten a JSON tree into the RequestField key / value store key values are build by joining all path names with " _ " where path names are : keys for objects ; indices for lists .
depth_budget
usize
args
&mut RequestField
prefix
&mut Vec<String>
value
Value