Click here to Skip to main content
12,823,404 members (47,750 online)
Rate this:
Please Sign up or sign in to vote.
See more: ASP.NET
Hello All,
I don't have any idea how to read and write Json file in c#, but in my project client requirment is to implement Json, so please help me if any body have any URL or sample code where it is given the detail steps for using Json in

Details like Insert/update/delete data from Json file.

Thanking you in advance.
Posted 10-Oct-12 2:55am
Updated 10-Oct-12 3:07am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Json are simmilar to XML in terms of use but they are equivalent to txt file in terms of accessibility. you can use teh following code to read/write a jasoin file. you need to change the code as per your requirement.


//Open the file              
var stream = File.OpenText("json file.txt"); 
//Read the file              
string st = stream.ReadToEnd();                           
var jsonArray = JsonArray.Parse(st);              
foreach (var item in jsonArray)              
JsonObject ob = new JsonObject(item);                   
foreach (var t in ob.Values)                  
JsonObject oo = new JsonObject(t);                       
foreach (var x in oo)                      
textBox1.AppendText(x.Key + " : " + x.Value + "\n");                      


KeyValuePair<string, JsonValue> pair = new KeyValuePair<string, JsonValue>("FName","Sourabh");             
KeyValuePair<string, JsonValue> pair2 = new KeyValuePair<string, JsonValue>("LName", "SInha");              
List<KeyValuePair<string, JsonValue>> list = new List<KeyValuePair<string, JsonValue>>();             
JsonObject jObject = new JsonObject(list);             
var stream = new StreamWriter("json out file.txt");             
foreach (var x in jObject)             
//  textBox1.AppendText(x.Key + " : " + x.Value + "\n");                 
textBox1.AppendText(x.ToString() + "\n");                 
stream.WriteLine(x.ToString() + "\n");             
JsonArray jarray = new JsonArray("item1","item2","Item3");             
foreach (var x in jarray)             


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170308.1 | Last Updated 10 Oct 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100