Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

c# write to file in json

//if you want to use a list and add it to a file in json do this
using System.IO;
using System.Text.Json;

List<Data> data = new List<Data>();
  public void SaveData()
        {
            using (StreamWriter sw = File.CreateText("data.json"))
            {
                sw.Write(JsonSerializer.Serialize(data));
            }
        }
Comment

c# write json to file

using System.Text.Json;
using System.Text.Json.Serialization;

List<data> _data = new List<data>();
_data.Add(new data()
{
    Id = 1,
    SSN = 2,
    Message = "A Message"
});

using FileStream fileStream = File.Create(@"D:path.json");
await JsonSerializer.SerializeAsync(createStream, _data);
Comment

Write JSON file C#

using System.Text.Json;
using System.Text.Json.Serialization;

List<data> _data = new List<data>();
_data.Add(new data()
{
    Id = 1,
    SSN = 2,
    Message = "A Message"
});

string json = JsonSerializer.Serialize(_data);
File.WriteAllText(@"D:path.json", json);
Comment

# write json file

# write json file
import json
d = {
    "firstName": "Tom",
    "lastName": "Jack",
    "gender": "male",
    "age": 35,
    "address": {
        "streetAddress": "126",
        "city": "San Jone",
        "state": "CA",
        "postalCode": "95150"
    },
    "phoneNumbers": [
        { "type": "home", "number": "4083627627" }
    ]
}

filename = "/content/sample_data/sample1.json"
with open(filename, 'w') as f:
  json.dump(d, f)
  
Comment

how to create json file in c#

//open file stream
using (StreamWriter file = File.CreateText(@"D:path.txt"))
{
     JsonSerializer serializer = new JsonSerializer();
     //serialize object directly into file stream
     serializer.Serialize(file, _data);
}
Comment

how to create json file in c#

            File.Create(@"details.json");
Comment

PREVIOUS NEXT
Code Example
Javascript :: mongodb sort objectid 
Javascript :: lyrics api 
Javascript :: set attribute in javascript 
Javascript :: set timeout 
Javascript :: js and 
Javascript :: how to remove last element in js 
Javascript :: data type in javascript 
Javascript :: multipline and single line regex pattern 
Javascript :: axios Request body larger than maxBodyLength limit 
Javascript :: react native apk bundle 
Javascript :: how to comment in a json file 
Javascript :: foreach over array javascript 
Javascript :: add tab to textarea javascript 
Javascript :: jquery form data 
Javascript :: vuex state from another module 
Javascript :: js get html content 
Javascript :: array length javascript 
Javascript :: remove classname to node 
Javascript :: jquery header basic auth 
Javascript :: js create array from for loop 
Javascript :: chalk js 
Javascript :: on refresh react url not working or 404 page not showing react 
Javascript :: how to get checked value of checkbox in jquery 
Javascript :: detect iframe content change javascript 
Javascript :: formik and yup reactjs 
Javascript :: find and filter in javascript 
Javascript :: get left position based on container jquery 
Javascript :: get query parameters in node.js 
Javascript :: express param in url 
Javascript :: js sum of int in array 
ADD CONTENT
Topic
Content
Source link
Name
3+6 =