pub fn sort(value: Value, args: HashMap<String, Value>) -> Result<Value> {
    let arr = try_get_value!("sort", "value", Vec<Value>, value);
    if arr.is_empty() {
        return Ok(arr.into());
    }

    let attribute = match args.get("attribute") {
        Some(val) => try_get_value!("sort", "attribute", String, val),
        None => String::new(),
    };
    let ptr = match attribute.as_str() {
        "" => "".to_string(),
        s => get_json_pointer(s),
    };

    let first = arr[0]
        .pointer(&ptr)
        .ok_or_else(|| format!("attribute '{}' does not reference a field", attribute))?;

    let mut strategy = get_sort_strategy_for_type(first)?;
    for v in &arr {
        let key = v
            .pointer(&ptr)
            .ok_or_else(|| format!("attribute '{}' does not reference a field", attribute))?;
        strategy.try_add_pair(v, key)?;
    }
    let sorted = strategy.sort();

    Ok(sorted.into())
}
/// Sorts the array in ascending order.
/// Use the 'attribute' argument to define a field to sort by.
Sorts the array in ascending order.
Use the 'attribute' argument to define a field to sort by.
Sorts the array in ascending order . Use the ' attribute ' argument to define a field to sort by .
pub fn sort(value: Value, args: HashMap<String, Value>) -> Result<Value> {
    let arr = try_get_value!("sort", "value", Vec<Value>, value);
    if arr.is_empty() {
        return Ok(arr.into());
    }
    let attribute = match args.get("attribute") {
        Some(val) => try_get_value!("sort", "attribute", String, val),
        None => String::new(),
    };
    let ptr = match attribute.as_str() {
        "" => "".to_string(),
        s => get_json_pointer(s),
    };
    let first = arr[0]
        .pointer(&ptr)
        .ok_or_else(|| format!("attribute '{}' does not reference a field", attribute))?;
    let mut strategy = get_sort_strategy_for_type(first)?;
    for v in &arr {
        let key = v
            .pointer(&ptr)
            .ok_or_else(|| format!("attribute '{}' does not reference a field", attribute))?;
        strategy.try_add_pair(v, key)?;
    }
    let sorted = strategy.sort();
    Ok(sorted.into())
}
pub fn sort ( value : Value , args : HashMap < String , Value > ) -> Result < Value > { let arr = try_get_value ! ( " " " " Vec Value value ) ; if arr . is_empty ( ) { return Ok ( arr . into ( ) ) ; } let attribute = match args . get ( " " ) { Some ( val ) => try_get_value ! ( " " " " String val ) , None => String :: new ( ) , } ; let ptr = match attribute . as_str ( ) { " " => " " . to_string ( ) , s => get_json_pointer ( s ) , } ; let first = arr [ 0 ] . pointer ( & ptr ) . ok_or_else ( | | format ! ( " " attribute ) ) ? ; let mut strategy = get_sort_strategy_for_type ( first ) ? ; for v in & arr { let key = v . pointer ( & ptr ) . ok_or_else ( | | format ! ( " " attribute ) ) ? ; strategy . try_add_pair ( v , key ) ? ; } let sorted = strategy . sort ( ) ; Ok ( sorted . into ( ) ) }
Sorts the array in ascending order.
Sorts the array in ascending order .
value
Value
args
HashMap<String, Value>
value
Value
args
HashMap<String, Value>