Brian Dunning's FileMaker Custom Functions

JSON.ArraySort ( array ; nestedPath ; fmDataType ; direction ; sortLocale )

Sort a json array.

  Be the first to rate this function Log in to vote

Josh Willing   Josh Willing - Show more from this author
Willing Apps

  Sample input:
JSON.ArraySort("[5, 3, 8, 1, 2]"; ""; "number"; "asc"; "")
  Sample output:
[1,2,3,4,5]

  Function definition: (Copy & paste into FileMaker's Edit Custom Function window)

Sort an array by the value at `nestedPath` (leave empty if the array does not contain objects/arrays). Specify `fmDataType` to interpret the value at `nestedPath` as a specific filemaker data type, e.g. text/date/time/timestamp/number. Specify asc/desc for direction. And specify the sortLocale if needed to sort text for different locales.

This functions should gracefully handle both comma and periods as decimal separators. Please see the CF header for other caveats.


Examples:

Input: JSON.ArraySort("[5, 3, 8, 1, 2]"; ""; "number"; "asc"; "")
Output: [1,2,3,4,5]

Input: JSON.ArraySort("[{\"user\": {\"age\": 35}}, {\"user\": {\"age\": 21}}, {\"user\": {\"age\": 42}}]"; "user.age"; "number"; "asc"; "")
Output: [{"user":{"age":21}},{"user":{"age":35}},{"user":{"age":42}}]

 

Comments

Log in to post comments.

 

Note: these functions are not guaranteed or supported by BrianDunning.com. Please contact the individual developer with any questions or problems.

Support this website.

This library has been a free commmunity resource for FileMaker users and developers for 21 years. It receives no funding and has no advertisements. If it has helped you out, I'd really appreciate it if you could contribute whatever you think it's worth: