C
C#•2mo ago
Core Dream

JSON Deserialization Multiple Entries

Hello. Is there an easy way to enumerate through this .json and pull out the data I need onto a UI? Stuff like Prop ID, Prop Name, etc. Of courses there's multiple props per .json so I'd need to be able to deserialize them all, edit them, and reserialize back.
{
"data": [
{
"prop_name": "Invalid",
"unk_14": 3728923965
},
{
"prop_id": 3,
"prop_name": "Ringbell",
"state": 1,
"mdl_path": 7636114012738718880,
"mtls_path": 5207710352904117017,
"prop_config_jsfb_path": 17346466537390459746,
"textures_path": 983795090616222792,
"unk_14": 3440520905
},
{
"prop_id": 4,
"type": 3,
"prop_name": "Dent_able_Chair_Black",
"state": 1,
"mdl_path": 11920831628306830712,
"mtls_path": 2176307239327909185,
"prop_config_jsfb_path": 18365218056640542593,
"textures_path": 1591327919772567142,
"havok_path": 17825444133106620151,
"sdb_name_id": 3419942826,
"render_path_1": 14812650683656359252,
"render_path_2": 3410622199164832471,
"unk_14": 433605154
},
{
"prop_id": 5,
"type": 1,
"prop_name": "table",
"state": 1,
"mdl_path": 3544448472792293094,
"mtls_path": 9384549906439149407,
"prop_config_jsfb_path": 18081587626750211327,
"ycl_path": 16030772999323866325,
"textures_path": 7145355447320130403,
"havok_path": 14679784151747246516,
"sdb_name_id": 968076457,
"render_path_1": 6628166879056395409,
"render_path_2": 7014051501087692342,
"unk_14": 3954428193
}
]
}
{
"data": [
{
"prop_name": "Invalid",
"unk_14": 3728923965
},
{
"prop_id": 3,
"prop_name": "Ringbell",
"state": 1,
"mdl_path": 7636114012738718880,
"mtls_path": 5207710352904117017,
"prop_config_jsfb_path": 17346466537390459746,
"textures_path": 983795090616222792,
"unk_14": 3440520905
},
{
"prop_id": 4,
"type": 3,
"prop_name": "Dent_able_Chair_Black",
"state": 1,
"mdl_path": 11920831628306830712,
"mtls_path": 2176307239327909185,
"prop_config_jsfb_path": 18365218056640542593,
"textures_path": 1591327919772567142,
"havok_path": 17825444133106620151,
"sdb_name_id": 3419942826,
"render_path_1": 14812650683656359252,
"render_path_2": 3410622199164832471,
"unk_14": 433605154
},
{
"prop_id": 5,
"type": 1,
"prop_name": "table",
"state": 1,
"mdl_path": 3544448472792293094,
"mtls_path": 9384549906439149407,
"prop_config_jsfb_path": 18081587626750211327,
"ycl_path": 16030772999323866325,
"textures_path": 7145355447320130403,
"havok_path": 14679784151747246516,
"sdb_name_id": 968076457,
"render_path_1": 6628166879056395409,
"render_path_2": 7014051501087692342,
"unk_14": 3954428193
}
]
}
(WinForms but it dont matter)
31 Replies
The Fog from Human Resources
you could use Model classes wait ill look for my example
The Fog from Human Resources
with this approach you can easily create objects from your JSON and use it in your applications
Core Dream
Core Dream•2mo ago
thx, i had a feeling it was model based its from flatbuffers converted to json, sadly, i dont own or know the original schema but this will do
Core Dream
Core Dream•2mo ago
i appreciate your fast response
The Fog from Human Resources
this is very simple to setup i love this approach a lot no problem!
Core Dream
Core Dream•2mo ago
game modding can be fun but tedious (OFFLINE ONLY) Whats your take on Codeium + actually coding ? like a sidekick
The Fog from Human Resources
honestly ive never heard of it :SCgetoutofmyhead: is it that AI assistant?
Core Dream
Core Dream•2mo ago
yeah i found it on Free Media Heck Yeah its supposed to be better than Copilot i prefer to code myself and read but its helpful maybe lol
Core Dream
Core Dream•2mo ago
Codeium · Free AI Code Completion & Chat
Codeium offers best in class AI code completion, search, and chat — all for free. It supports over 70+ languages and integrates with your favorite IDEs, with lightning fast speeds and state-of-the-art suggestion quality.
The Fog from Human Resources
honestly if you can code, AI can be a powerful assistant, as long as you can work with the outcome its fine i regularily use Chat GPT to ask questions abt concepts to implement, if im unsure ill just have a convo with the people here so as long as you know what youre doing youre good to go tbh
Core Dream
Core Dream•2mo ago
yeah AI is not fool proof of course, id never use it for production just on stuff i need a hint for etc bet @Thing from Human Resources Have you used a TreeView?
Core Dream
Core Dream•2mo ago
No description
Core Dream
Core Dream•2mo ago
having issues getting it to populate the data is outputting fine otherwise XD
public class GetData
{
public static void DeserializePropData(string jsonFile, TreeView treeView)
{
string jsonString = File.ReadAllText(jsonFile);
RootObject root = JsonConvert.DeserializeObject<RootObject>(jsonString);

// Call a method to add nodes to the TreeView
AddNodesToTreeView(treeView, root.data);
}

static void AddNodesToTreeView(TreeView treeView, List<DataEntry> data)
{
// Add nodes to the TreeView
foreach (var entry in data)
{
// Create a parent node
TreeNode parentNode = new TreeNode($"Property ID: {entry.prop_id}, Property Name: {entry.prop_name}, State: {entry.state}");

// Add the parent node to the TreeView
treeView.Nodes.Add(parentNode);
}
}
}
public class GetData
{
public static void DeserializePropData(string jsonFile, TreeView treeView)
{
string jsonString = File.ReadAllText(jsonFile);
RootObject root = JsonConvert.DeserializeObject<RootObject>(jsonString);

// Call a method to add nodes to the TreeView
AddNodesToTreeView(treeView, root.data);
}

static void AddNodesToTreeView(TreeView treeView, List<DataEntry> data)
{
// Add nodes to the TreeView
foreach (var entry in data)
{
// Create a parent node
TreeNode parentNode = new TreeNode($"Property ID: {entry.prop_id}, Property Name: {entry.prop_name}, State: {entry.state}");

// Add the parent node to the TreeView
treeView.Nodes.Add(parentNode);
}
}
}
other class
Core Dream
Core Dream•2mo ago
No description
Core Dream
Core Dream•2mo ago
got it so far
Core Dream
Core Dream•2mo ago
No description
Core Dream
Core Dream•2mo ago
Thank you so much I've made huge improvements since 🙂 here's a dumb question
Core Dream
Core Dream•2mo ago
No description
Core Dream
Core Dream•2mo ago
No description
Core Dream
Core Dream•2mo ago
how do i handle nulls? not every entry has the same field
using System.Text.Json.Serialization;

namespace GameModderStudio.Core.Model;

public class PropsData_AssetMap
{
[JsonPropertyName("prop_id")]
public int prop_id { get; set; }

[JsonPropertyName("type")]
public int type { get; set; }

[JsonPropertyName("prop_name")]
public string? prop_name { get; set; }

[JsonPropertyName("state")]
public int state { get; set; }

[JsonPropertyName("mdl_path")]
public ulong mdl_path { get; set; }

[JsonPropertyName("mtls_path")]
public ulong mtls_path { get; set; }

[JsonPropertyName("prop_config_jsfb_path")]
public ulong prop_config_jsfb_path { get; set; }

[JsonPropertyName("textures_path")]
public ulong textures_path { get; set; }

[JsonPropertyName("havok_path")]
public ulong havok_path { get; set; }

[JsonPropertyName("sdb_name_id")]
public uint sdb_name_id { get; set; }

[JsonPropertyName("render_path_1")]
public ulong render_path_1 { get; set; }

[JsonPropertyName("render_path_2")]
public ulong render_path_2 { get; set; }

[JsonPropertyName("unk_14")]
public uint unk_14 { get; set; }
}
using System.Text.Json.Serialization;

namespace GameModderStudio.Core.Model;

public class PropsData_AssetMap
{
[JsonPropertyName("prop_id")]
public int prop_id { get; set; }

[JsonPropertyName("type")]
public int type { get; set; }

[JsonPropertyName("prop_name")]
public string? prop_name { get; set; }

[JsonPropertyName("state")]
public int state { get; set; }

[JsonPropertyName("mdl_path")]
public ulong mdl_path { get; set; }

[JsonPropertyName("mtls_path")]
public ulong mtls_path { get; set; }

[JsonPropertyName("prop_config_jsfb_path")]
public ulong prop_config_jsfb_path { get; set; }

[JsonPropertyName("textures_path")]
public ulong textures_path { get; set; }

[JsonPropertyName("havok_path")]
public ulong havok_path { get; set; }

[JsonPropertyName("sdb_name_id")]
public uint sdb_name_id { get; set; }

[JsonPropertyName("render_path_1")]
public ulong render_path_1 { get; set; }

[JsonPropertyName("render_path_2")]
public ulong render_path_2 { get; set; }

[JsonPropertyName("unk_14")]
public uint unk_14 { get; set; }
}
heres the deserialize method
public static void DeserializePropDataAssets(DataGridView dataGridView, string jsonFile, ref RootObject root)
{
string jsonString = File.ReadAllText(jsonFile);
root = JsonConvert.DeserializeObject<RootObject>(jsonString);

dataGridView.Rows.Clear();
dataGridView.Columns.Clear();

dataGridView.Columns.Add("prop_id", "ID");
dataGridView.Columns.Add("type", "Type");
dataGridView.Columns.Add("prop_name", "Name");
dataGridView.Columns.Add("state", "State");
dataGridView.Columns.Add("mdl_path", "MDL Path");
dataGridView.Columns.Add("mtls_path", "MTLs Path");
dataGridView.Columns.Add("prop_config_jsfb_path", "Prop Config Path");
dataGridView.Columns.Add("textures_path", "Textures Folder Path");
dataGridView.Columns.Add("havok_path", "Havok Folder Path");
dataGridView.Columns.Add("sdb_name_id", "SDB Hash ID");
dataGridView.Columns.Add("render_path_1", "Render 1 Path");
dataGridView.Columns.Add("render_path_2", "Render 2 Path");
dataGridView.Columns.Add("unk_14", "Unk 14");

foreach (var entry in root.data)
{
dataGridView.Rows.Add(
entry.prop_id,
entry.type,
entry.prop_name,
entry.state,
entry.mdl_path,
entry.mtls_path,
entry.prop_config_jsfb_path,
entry.textures_path,
entry.havok_path,
entry.sdb_name_id,
entry.render_path_1,
entry.render_path_2,
entry.unk_14);
}
}
public static void DeserializePropDataAssets(DataGridView dataGridView, string jsonFile, ref RootObject root)
{
string jsonString = File.ReadAllText(jsonFile);
root = JsonConvert.DeserializeObject<RootObject>(jsonString);

dataGridView.Rows.Clear();
dataGridView.Columns.Clear();

dataGridView.Columns.Add("prop_id", "ID");
dataGridView.Columns.Add("type", "Type");
dataGridView.Columns.Add("prop_name", "Name");
dataGridView.Columns.Add("state", "State");
dataGridView.Columns.Add("mdl_path", "MDL Path");
dataGridView.Columns.Add("mtls_path", "MTLs Path");
dataGridView.Columns.Add("prop_config_jsfb_path", "Prop Config Path");
dataGridView.Columns.Add("textures_path", "Textures Folder Path");
dataGridView.Columns.Add("havok_path", "Havok Folder Path");
dataGridView.Columns.Add("sdb_name_id", "SDB Hash ID");
dataGridView.Columns.Add("render_path_1", "Render 1 Path");
dataGridView.Columns.Add("render_path_2", "Render 2 Path");
dataGridView.Columns.Add("unk_14", "Unk 14");

foreach (var entry in root.data)
{
dataGridView.Rows.Add(
entry.prop_id,
entry.type,
entry.prop_name,
entry.state,
entry.mdl_path,
entry.mtls_path,
entry.prop_config_jsfb_path,
entry.textures_path,
entry.havok_path,
entry.sdb_name_id,
entry.render_path_1,
entry.render_path_2,
entry.unk_14);
}
}
but not sure how to handle unk_13 which some entries have and some even have a unk_0 inside the unk_13's etc probably need a dictionary and jobject parse there, i'll toy with it later
The Fog from Human Resources
dont use Newtonsoft json
Mayor McCheese
Mayor McCheese•2mo ago
do you need those at all?
Core Dream
Core Dream•2mo ago
yep, its part of the flatbuffer, but not ALL entries have one Can you do an example w/o it? (I assume System.Text.Json)
The Fog from Human Resources
1. If your property names match the JSON name you dont need the extra [JsonPropertyName], you can use this however to assign json key state for a variable called State tho (this would be more appropriate for C# naming conventions too) 2. You can just do MyObject test = JsonSerializer.Deserialize<MyObject>(myJsonString);
Mayor McCheese
Mayor McCheese•2mo ago
I think you're in custom (de)serialization territory.
Core Dream
Core Dream•2mo ago
yep, that be a given
Mayor McCheese
Mayor McCheese•2mo ago
There's some trial and error that goes on there, any time I need to do it, it's across years. So I'm basically starting over with the docs
Core Dream
Core Dream•2mo ago
Yeah, since the schemas are unknown, its a game modding thing so no one is going to have them except the devs of course. I mean I know the fields 90%. But how come so many say use System.Text.Json over Newtonsoft's? Besides Newtownsoft's being outdated.
Mayor McCheese
Mayor McCheese•2mo ago
oh it's game modding
Want results from more Discord servers?
Add your server