r/AskProgramming • u/gurrenm3 • Jul 19 '26
Other Advice on the structure of my JSON file?
Hello! I've been working on a modding framework that makes it easier to make mods for games written in C++. The main idea is that it's storing info about how to reverse engineer/discover game data like function addresses and field offsets.
I've got an example JSON file below that describes how to find the function for giving money to the player, and the field offset for the money variable. Each location style is not required and its just to demonstrate that multiple methods could be stored/used simultaneously. Also in this example, I'm trying to reuse property names ('kind', 'result', 'cached-location', etc) even though they're in slightly different contexts, in order to keep it more consistent and simple for less experienced programmers.
Example JSON:
{
"header" : {
"header-version": "1.0.0.0",
"file-type": "data-locations",
"module": "NMS.exe",
"module-last-modified": "Friday, March 10, 2023, 2:04:54 AM",
},
"data" : [
{
"id": "cGcPlayerState.units",
"locations" : [
{ "kind": "cached-location", "value": "0x1BC" },
{ "kind": "pattern", "value": "8B 83 ? ? ? ? 48 83 C4 ? 5B C3 CC CC CC CC CC CC CC CC CC 40 53", "result": "memory-displacement" },
{ "kind": "pattern", "value": "44 89 81 ? ? ? ? 4C 8B 15 ? ? ? ? 8B D6", "result": "memory-displacement" },
{
"kind": "pattern",
"value": "44 8B 81 ? ? ? ? 48 8D 2D",
"result": {
"kind": "memory-displacement",
"instruction-offset": 0,
"operand-index": 1
}
}
]
},
{
"id": "cGcPlayerState.AwardUnits",
"locations" : [
{ "kind": "cached-location", "value": "0x1403CF8E0" },
{ "kind": "export", "value": "?AwardUnits@cGcPlayerState@@QEAAIH@Z" },
{ "kind": "pattern", "value": "48 89 5C 24 ? 48 89 6C 24 ? 48 89 74 24 ? 57 48 83 EC ? 44 8B 81 ? ? ? ? 48 8D 2D", "result-kind" : "matched-target-address" },
{ "kind": "pattern", "value": "E8 ? ? ? ? E9 ? ? ? ? 48 8B 0D ? ? ? ? 48 8D 54 24 ? 44 8B 44 24", "result-kind" : "relative-target-address" },
{ "kind": "pattern", "value": "E8 ? ? ? ? 4C 89 64 24 ? 48 8D 15 ? ? ? ? 0F 28 DE F3 0F 11 7C 24 ? 41 B8 ? ? ? ? 48 8D 0D ? ? ? ? E8 ? ? ? ? 84 C0 74 ? 48 8B 0D ? ? ? ? 8B D3", "result-kind" : "relative-target-address" },
{
"kind": "search",
"identifiers": [
{
"target": "function",
"operation": "contains",
"values": [
{ "kind": "string", "value": "MONEY" },
{ "kind": "string", "value": "MONEY_EVER" }
]
},
{
"target": "arg1",
"operation": "contains-offset",
"values": [
"cGcPlayerState.AwardUnits.arg1.offset1",
"cGcPlayerState.AwardUnits.arg1.offset2"
]
},
{
"target": "arg2",
"operation": "offset-qty",
"value": "0"
},
{
"target": "cGcPlayerState.AwardUnits.arg1.offset1",
"operation": "add",
"value": "cGcPlayerState.AwardUnits.arg2"
},
{
"target": "cGcPlayerState.AwardUnits.arg1.offset2",
"operation": "add",
"value": "1"
},
{
"target": "function",
"operation": "return",
"value": "cGcPlayerState.AwardUnits.arg1.offset1"
}
]
}
]
},
{
"id": "cGcPlayerState.AwardUnits.arg1.offset1",
"locations" : [
{ "kind": "cached-location", "value": "0x1BC" },
{ "kind": "pattern", "value": "8B 83 ? ? ? ? 48 83 C4 ? 5B C3 CC CC CC CC CC CC CC CC CC 40 53", "result-kind" : "memory-displacement" }
]
},
{
"id": "cGcPlayerState.AwardUnits.arg1.offset2",
"locations" : [
{ "kind": "cached-location", "value": "0x148" },
{ "kind": "pattern", "value": "48 FF 83 ? ? ? ? 8B 83 ? ? ? ? 48 8B 5C 24 ? 48 8B 6C 24 ? 48 8B 74 24 ? 48 83 C4 ? 5F C3 CC CC CC CC CC", "result-kind" : "memory-displacement" }
]
}
]
}
My main design goals are:
- Create a long-term solution for mod makers to use to store this kind of data. Must be flexible and capable of expanding to their needs.
- To keep the JSON format easy and intuitive for mod makers
- Provide multiple methods of locating the same thing. This will also be extensible so mod authors could make their own location kinds.
- The structure must be able to grow overtime without causing major breaking changes and is why I'm using a header.
- Be compatible with multiple JSON files simultaneously
- Allow the header to specify a "file-type" and then have different types of data objects.
I would love to hear any feedback on the structure of this. I've spent years on it, and I really want to make something that makes a difference for people. It's really important to me that its an appealing structure for people to use and is able to meet the technical requirements of the system. Some other things that would be nice to get feedback on are:
- Overall structure of the file
- Whether its okay to use the property name 'kind' over and over in slightly different contexts.
- Supporting multiple files with different 'file-type' values, so everything is very similar with the data object being the only thing that changes.
- Allowing properties like "result" to have both compact and expanded forms
- using dashes '-' for property-names instead of camelCase
- Any long-term concerns or unpleasantness you see
Thank you in advance!
6
u/CorpT Jul 19 '26
.... It's a JSON file.
1
u/Xirdus Jul 19 '26
I kinda doubt the usefulness of the whole idea. What exactly is the use case here? Create a common set of tools that can be used to mod any game regardless of engine? That's just not going to work, games are too different from each other for this kind of common tooling to make sense. Create an information exchange format for people to easily build their own game-specific tools? Creating a file in your format is about as much effort as building the tool itself, why would anyone choose the former if they could do the latter?
As for the file format. It's extremely verbose. Not a good thing. Also, putting "file type" inside your file format is not extensibility - it's an invitation to cram multiple incompatible formats into the same spec. Version number can be good or bad. It's basically a warning telling the user there will be breaking changes in the future. It's good when you do want to permit yourself to make breaking changes to the format, which is most of the time. But if you want old tooling to work in perpetuity with files produced by new tooling, you really don't want to do it.
Repeating names is neither good nor bad. Don't reuse name for the sake of reuse - it will only confuse users. Don't avoid reuse for the sake of avoiding reuse - it will only confuse the users. Always pick whatever name makes the most sense in the context, regardless of what names you used elsewhere in the file.
Dashes are not valid identifier characters in most programming languages. Working with your file format will be ever so slightly more annoying than it could be if it used camelCase.
1
u/mredding Jul 20 '26
As a C++ engineer of 37 years, I frankly don't care what any of this means so long as it's documented.
As for the file contents and format - JSON is a transport protocol, it makes for a very poor file format as it's strictly hierarchical, and there's no inherent reuse. I see patterns in your data that would be better served with type templates (not in the C++ sense, but in some sort of macro sense) and parameters. The verbosity of your data format favors "SAX" aka event-driven parsing, but the JSON data format does not particularly favor the human element, since we're not the principle audience - the data is only text for being portable, and only so happens to be readable effectively for debugging the greater application.
I would think you would want a format that explicitly favored describing types, their layouts, their methods, their hierarchies, and all their associated patterns and offsets. If you had a tool that assisted in the discovery of such things - then persisting that information is a secondary function of the program, and it wouldn't matter what the format was, since your program would be it's own consumer. But if you expect people to read and modify this data on a first hand basis, this isn't optimal.
That said, anyone serious about whatever their endeavor, they'll see past design flaws in favor of the end goal - just so long as the tool facilitates that goal at all. It's a means to an end at that point.