Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

369
Views
Read/Write JSON using System.Text.Json

We are using NewtwonSoft.json currently but need to move to System.Text.JSON for security reasons.

So we are new to System.Text.JSON and are having trouble reading the following JSON file.

Ideally we would like to read and eventually put each record in a separate row in a Grid with the ID, Name and ContractTypeID as Columns A, B and C. Prefer VB.net but googling has led us to believe VB.net is not supported much in System.Text.JSON. So C# will work. Appreciate any feed back that would get us going. We have tried using a practice C# Project but get error:

"System.Text.Json.JsonReaderException: ''0xEF' is an invalid start of a value. LineNumber: 0 | BytePositionInLine: 0." at the line Reader.Read.

var fileName = @"D:\MyFile.json";

byte[] data = System.IO.File.ReadAllBytes(fileName);

Utf8JsonReader reader = new Utf8JsonReader(data);

while (reader.Read())
[
    {
         "ID": "001",
         "Name": "INT SYS CO",
         "ContractTypeID": "CPAF"
    },
    {
         "ID": "002",
         "Name": "PLT",
         "ContractTypeID": "CPFF"
    },
    {
         "ID": "003",
         "Name": "SBAND",
         "ContractTypeID": "CPIF"
    },
    {
         "ID": "004",
         "Name": "SE",
         "ContractTypeID": "CPIF_PI"
    },
    {
         "ID": "005",
         "Name": "SPE",
         "ContractTypeID": "FFP"
    }
]
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Obviously the file is saved in UTF-8 encoding with BOM.

If the file contains a UTF-8 byte order mark, remove it before passing the bytes to the Utf8JsonReader.

 ReadOnlySpan<byte> data = File.ReadAllBytes(fileName); ReadOnlySpan<byte> utf8Bom = new byte[] { 0xEF, 0xBB, 0xBF }; if (data.StartsWith(utf8Bom)) { data = data.Slice(utf8Bom.Length); } Utf8JsonReader reader = new Utf8JsonReader(data);

See more in the documentation .

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!