Sooraj
Sooraj

Reputation: 133

Updating a specific item present in a JSON File using C#

In my application, I am using a json file to persist the details in my application to use it in offline situation. Suppose if I serialize and save the data in my application and later point I need to update only one item in the json file.

In the above situation, is it possible to update only the delta change without overtiring the entire json back to the file.

Upvotes: 0

Views: 444

Answers (2)

P. Roe
P. Roe

Reputation: 2117

Writing the whole file is the way this is usually accomplished. If you need to update a single config value then perhaps you should save your data to a database instead of a json text file. Redis, for example is a File based database and you could easily use it as the source of your application's configuration. This would allow you to make updates at the same level of granularity that you're looking for.

Upvotes: 1

Milney
Milney

Reputation: 6427

Only if the value and the replacement were the exact same size...

If you are saving enough data to make this a concern maybe JSON isn't the correct format to store it in, consider a database

Upvotes: 3

Related Questions