Data Encoding
Now that we know how data is stored conceptually, let’s see how to store it practically in a way that computers can understand it.
Text Encoding
Section titled “Text Encoding”Text is a decent choice since it’s human readable. That’s great since many of the people reading this article are likely humans themselves!
Let’s take a look at two of the most common formats you’ll come across, XML and JSON. Sims 4 uses XML. JSON is common in general.
<?xml version="1.0" encoding="UTF-8" ?><People> <!-- XML allows comments! --> <!-- Comments are for documentation and don't affect the data. --> <Person socialSecurityNumber="85037826"> <firstName>John</firstName> <lastName>Smith</lastName> <age>45</age> </Person> <Person socialSecurityNumber="79815634"> <firstName>Rachel</firstName> <lastName>Doe</lastName> <age>39</age> </Person></People>[ { "firstName": "John", "lastName": "Smith", "age": 45, "socialSecurityNumber": 85037826 }, { "firstName": "Rachel", "lastName": "Doe", "age": 39, "socialSecurityNumber": 79815634 }]Note that XML allows encoding data directly in the node itself via an attribute, as shown with socialSecurityNumber.
These formats should be fairly self explanatory, but if you have any trouble there are countless resources available. I’d suggest the w3schools.com tutorials for XML and JSON.
Binary Advanced, Optional
Section titled “Binary ”Text is great if we want humans to read the data, but what if we don’t care about that? In that case, binary is a much better choice as it is far more efficient. The caveat is that is that it requires knowing the data format ahead of time, and the data is encoded directly. A rough example using the same data from before:
2 John Smith 45 85037826 Rachel Doe 39 79815634This is still technically text and some details are glossed over, but this is conceptually what binary looks like. The first 2 indicates the number of People, then each person’s data is written directly with no extra fluff.
Many of Sims 4’s resources use custom binary types (including the .package file type itself), which is why Sims 4 Editor and Sims 4 Studio are required to edit them.