Click here to Skip to main content
15,867,686 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
1. The json (Array) format:
[
  {
    "Group": "1",
    "ID": 1,
    "Name": "User1",
    "Description": "Desc1"
  },
  {
    "Group": "2",
    "ID": 3,
    "Name": "DeleteMe",
    "Description": "Desc2"
  },
  {
    "Group": "3",
    "ID": 2,
    "Name": "User3",
    "Description": "Desc3"
  }
]


Desired output, by deleting object that has ID == 3:
[
  {
    "Group": "1",
    "ID": 1,
    "Name": "User1",
    "Description": "Desc1"
  },
  {
    "Group": "3",
    "ID": 2,
    "Name": "User3",
    "Description": "Desc3"
  }
]


2. Also how to to with json (Object) format:
{
  "Group": "1",
  "ID": 1,
  "Name": "User1",
  "Description": "Desc1"
},
{
  "Group": "2",
  "ID": 3,
  "Name": "DeleteMe",
  "Description": "Desc2"
},
{
  "Group": "3",
  "ID": 2,
  "Name": "User3",
  "Description": "Desc3"
}


Desired output, by deleting object that has ID == 3:
{
  "Group": "1",
  "ID": 1,
  "Name": "User1",
  "Description": "Desc1"
},
{
  "Group": "3",
  "ID": 2,
  "Name": "User3",
  "Description": "Desc3"
}


What I have tried:

I'm new on JSON, any assist would be great.
Posted
Updated 5-Nov-21 23:49pm
v2
Comments
Richard MacCutchan 6-Nov-21 4:41am    
"have tried many things"
What things? Unless you show us the code and explain what happens when you run it we cannot make suggestions to fix it.

1 solution

The way you do it is not to manipulate the JSON directly: you read the JSON data into C~ objects - that's what Newtonsoft is there for - manipulate the C# objects, then create new JSON data from them.

Manipulating the JSON directly is a PITA because it's text based and there are no "fixed points" to work from, including rows or even lines!
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900