Topics   All   MacOS (Only)   Windows (Only)   Linux (Only, Not)   iOS (Only, Not)  
Components   Crossplatform Mac & Win   Server   Client   Old   Deprecated   Guides   Examples   Videos
New in version: 10.1   10.2   10.3   10.4   10.5   11.0   11.1   11.2   11.3   11.4    Statistic    FMM    Blog  

JSON.SortWithEvaluate

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
MBS( "JSON.SortWithEvaluate"; json; Expression )   More

Parameters

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)"

Result

Returns OK or error.

Description

Sorts the JSON array/object using an expression to evaluate.
The expression is run every time two values are compared, so keep it quick. It should return 1 if leftJSON is smaller than rightJSON.

Our normal JSON.Sort is faster due to not having the overhead of evaluating expressions.

Examples

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\")" )

See also

Release notes

  • Version 10.2

Blog Entries

Created 9th April 2020, last changed 29th September 2020


JSON.Sort - JSON.ToHTML

Feedback: Report problem or ask question.




Links
MBS FileMaker Plugins

Start Chat