0

I have a JSON file containing some 15,000 keys. I'm writing an app which will edit the values of 8 keys without replacing anything else. So far I've managed to replace the entire file when editing an integer:

// currentDir = app directory
Dim fileReader As String
fileReader = My.Computer.FileSystem.ReadAllText(currentDir + "character.json")
Dim json As String = fileReader
Dim read = Newtonsoft.Json.Linq.JObject.Parse(json)

read.Item("Info")("Experience") = Convert.ToInt32(boxNewExp.Text)
Dim output As String = JsonConvert.SerializeObject(json, Newtonsoft.Json.Formatting.Indented)
IO.File.WriteAllText(currentDir + "character.json", output)

The answer in this question by agentnega is something that I tried to implement to no avail. I imagine I could use this method a bit better, but I haven't worked with VB for a while.

  • Consider using a database instead of a json file. The answer you linked still replaces the entire file. It is not that different from what you currently have. – Anu6is Oct 26 '21 at 11:27
  • @Anu6is Yes, I would if I could. The JSON file is part of a local storage profile linked to a game I play. The game does not utilize databases for storing profiles. – totalepremisere Oct 26 '21 at 13:18
  • 1
    You're going to find pretty much any solution is going to be replacing the entire file. Guessing you could go down the route of some lower level plain text handling using something along the lines of IO.File, probably a whole heap of overhead and complication though – Hursey Oct 26 '21 at 19:31
  • @Hursey Roger. I'm not actually against replacing the entire file, I just want the value itself to be changed. I have a feeling it's possible, but is there a post I could follow for that? – totalepremisere Oct 26 '21 at 20:00

0 Answers0