Skip to content

Instantly share code, notes, and snippets.

@bleroy
Created March 28, 2017 18:21
Show Gist options
  • Save bleroy/7879720551d779c20cdd4dbb36e78836 to your computer and use it in GitHub Desktop.
Save bleroy/7879720551d779c20cdd4dbb36e78836 to your computer and use it in GitHub Desktop.
JArray largeJson;
// read asynchronously from a file
using (FileStream asyncFileStream = new FileStream(@"large.json", FileMode.Open, FileAccess.Read, FileShare.Read, 4096, true))
{
largeJson = await JArray.LoadAsync(new JsonTextReader(new StreamReader(asyncFileStream)));
}
JToken user = largeJson.SelectToken("$[?(@.name == 'Woodard Caldwell')]");
user["isActive"] = false;
// write asynchronously to a file
using (FileStream asyncFileStream = new FileStream(@"large.json", FileMode.Open, FileAccess.Write, FileShare.Write, 4096, true))
{
await largeJson.WriteToAsync(new JsonTextWriter(new StreamWriter(asyncFileStream)));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment