sort the entries before writing to JSON