KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Utility method that sorts the properties of an object
PRODUCT: 4D | VERSION: 19 | PLATFORM: Mac & Win
Published On: June 13, 2022

When observing an object in the Debugger or Runtime Explorer, the expanded list of properties appears to be listed in a sorted fashion while the JSON representation of the object may appear differently. The appearance of the JSON is based on the order of creation for each property. The following utility method creates and returns a sorted copy of a given object.

// Method: Method: sortObjectProperties
#DECLARE($src_o : Object)->$return_o : Object
var $key_c : Collection
var $key_t : Text
$return_o:=New object
$key_c:=OB Keys($src_o).sort()
For each ($key_t; $key_c)
   $return_o[$key_t]:=$src_o[$key_t]
End for each