JSONEncoder has changed

Prior to Sonoma 14.0 and Xcode 15.0.1 my custom class was encoded in a consistent pattern that I exploited to append the file many thousands of times. Now, the encodings are of a seemingly random pattern that cannot be exploited to append. This may be a result of efforts to make the encoding more efficient or virtually any other reason.

My questions are:

  1. how do I revert to the previous JSONEncoder while using current OS & Xcode versions?, i.e, what files and in what locations do I restore?
  2. is it likely to be sustainable if I did so?

It has been previously noted that atomic files are not "append able" which is why I used JSON in the first place.

Any info or suggestion is appreciated. Thank you.

Answered by Scott in 771097022

If you mean the order of keys is now different (and you aren’t using the sortedKeys output option) then see this thread for discussion of why that is.

how do I revert to the previous JSONEncoder while using current OS & Xcode versions?

You can’t. That class is built into the Foundation framework in the operating system.

But one workaround could be to try the old JSONSerialization class. It’s not great with Swift but (when I tried this a while ago) you may get the old key ordering behavior, at least for now.

(Or is your issue different from key ordering? It’s not clear from the original question.)

Accepted Answer

If you mean the order of keys is now different (and you aren’t using the sortedKeys output option) then see this thread for discussion of why that is.

how do I revert to the previous JSONEncoder while using current OS & Xcode versions?

You can’t. That class is built into the Foundation framework in the operating system.

But one workaround could be to try the old JSONSerialization class. It’s not great with Swift but (when I tried this a while ago) you may get the old key ordering behavior, at least for now.

(Or is your issue different from key ordering? It’s not clear from the original question.)

Ah, thank you! Yes, using .sortedKeys returned the desired behavior. It is curious that this must have been a default as evidenced by consistent formatting for over a year, that is, until now. Thanks again.

JSONEncoder has changed
 
 
Q