I've a json file, and there is a comma in the end of JSON object. How to remove the last comma of Item2? Opening this file in the notepad++ having json viewer plugin/Format json removes the commas from Item1, Item2 and last json object.
Does PowerShell support reading this json and format properly like notepad++ does? Found this documentation https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/convertto-json?view=powershell-7.2
Did not find any options in ConvertTo-Json to format the json given below. And write same json again in correct format.
{
"Name": "SampleName",
"Cart": [
{
"Item1": "ItemOne",
},
{
"Item2": "ItemTwo",
},
]
}
Expected json output
{
"Name": "SampleName",
"Cart": [
{
"Item1": "ItemOne"
},
{
"Item2": "ItemTwo"
}
]
}
Jsonstring (only peeking/poking directly into the string might correct this, which I would discourage you to do). You should investigate how you created the sting/file as no respectedJsonserializer should allow this to happen.