Components | All | New | MacOS | Windows | Linux | iOS | ||||
Examples | Mac & Win | Server | Client | Guides | Statistic | FMM | Blog | Deprecated | Old |
Sorts the JSON array/object using an expression to evaluate.
Component | Version | macOS | Windows | Linux | Server | iOS SDK |
JSON | 10.2 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |
Parameter | Description | Example |
---|---|---|
json | A JSON text or reference. | [2,9,3,1] |
Expression | The expression to evaluate. Can include "leftJSON", "rightJSON" as variables. You can call other MBS JSON functions if needed. |
"(leftJSON) > GetAsNumber(rightJSON)" |
Returns OK or error.
Sort with evaluate:
MBS( "JSON.SortWithEvaluate"; "[2,9,3,1]"; "MBS( \"JSON.GetValue\"; leftJSON) < MBS( \"JSON.GetValue\"; rightJSON)" )
Sort a list of object by name:
MBS( "JSON.SortWithEvaluate"; "[
{\"name\": \"Joe\"},
{\"name\": \"Anna\"},
{\"name\": \"Tim\"},
{\"name\": \"John\"}
]"; "JSONGetElement ( leftJSON; \"name\") < JSONGetElement ( rightJSON; \"name\")" )
List files and sort by name:
MBS( "JSON.SortWithEvaluate";
MBS( "Files.ListAsJSON";
MBS("Folders.UserDesktop");
"Size" );
"JSONGetElement ( leftJSON; \"Name\") < JSONGetElement ( rightJSON; \"Name\")" )
List files and sort by size descending:
MBS( "JSON.SortWithEvaluate";
MBS( "Files.ListAsJSON";
MBS("Folders.UserDesktop");
"Size" );
"JSONGetElement ( leftJSON; \"Size\") > JSONGetElement ( rightJSON; \"Size\")" )
List files and sort by modification time stamp:
Let ( [
path = MBS("Folders.UserDesktop");
list = MBS( "Files.ListAsJSON"; path; "CreationTimeStamp¶ModificationTimeStamp" );
sort = MBS( "JSON.SortWithEvaluate"; list; "GetAsTimeStamp(JSONGetElement ( leftJSON; \"ModificationTimeStamp\")) < GetAsTimeStamp(JSONGetElement ( rightJSON; \"ModificationTimeStamp\"))" )
];sort)
This function checks for a license.
Created 9th April 2020, last changed 22nd May 2023