VS .net Repair function which reads 2 types of json documents
Budget: $10 – $30 USD
We have two different formats and one of the formats is failing. Attached is two files in the two formats. WI_Lakes_Sample.json works properly but WI_Populated_Places.json fails. We are looking for someone that could quickly correct the error.
We are getting the following error when reading one of our documents.
System.Text.Json.JsonException: 'The JSON value could not be converted to System.Collections.Generic.List`1[System.Decimal[]]. Path: $.features[0].geometry.coordinates[0] | LineNumber: 0 | BytePositionInLine: 126.'
This is the function that Fails
Dim newJSON As newJSON = JsonSerializer.Deserialize(Of newJSON)(json)
Private Sub BackgroundWorker1_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
Dim progress As IProgress(Of String) = DirectCast(e.Argument, IProgress(Of String))
Dim files As New List(Of String)
files.AddRange(Directory.GetFiles(TextBoxLocation.Text, "*.json", SearchOption.AllDirectories))
files.AddRange(Directory.GetFiles(TextBoxLocation.Text, "*.geojson", SearchOption.AllDirectories))
For Each strFile As String In files
progress.Report(String.Format("Compressing {0}", Chr(34) + strFile + Chr(34)) + vbNewLine)
Dim json As String = File.ReadAllText(strFile)
Dim newJSON As newJSON = JsonSerializer.Deserialize(Of newJSON)(json)
For Each feature As Feature In newJSON.features
Dim coordinates As List(Of List(Of Decimal())) = feature.geometry.coordinates
For Each coordinate As List(Of Decimal()) In coordinates
For Each d As Decimal() In coordinate
d(0) = Decimal.Round(Decimal.Parse(d(0)), maxLength)
d(1) = Decimal.Round(Decimal.Parse(d(1)), maxLength)
Next
Next
Next
Dim fileName As String = Path.GetFileNameWithoutExtension(strFile)
fileName = Path.Combine(Path.GetDirectoryName(strFile), fileName + "-compressed.json")
json = JsonSerializer.Serialize(newJSON)
File.WriteAllText(fileName, json)
Next
End Sub
We are getting the following error when reading one of our documents.
System.Text.Json.JsonException: 'The JSON value could not be converted to System.Collections.Generic.List`1[System.Decimal[]]. Path: $.features[0].geometry.coordinates[0] | LineNumber: 0 | BytePositionInLine: 126.'
This is the function that Fails
Dim newJSON As newJSON = JsonSerializer.Deserialize(Of newJSON)(json)
Private Sub BackgroundWorker1_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
Dim progress As IProgress(Of String) = DirectCast(e.Argument, IProgress(Of String))
Dim files As New List(Of String)
files.AddRange(Directory.GetFiles(TextBoxLocation.Text, "*.json", SearchOption.AllDirectories))
files.AddRange(Directory.GetFiles(TextBoxLocation.Text, "*.geojson", SearchOption.AllDirectories))
For Each strFile As String In files
progress.Report(String.Format("Compressing {0}", Chr(34) + strFile + Chr(34)) + vbNewLine)
Dim json As String = File.ReadAllText(strFile)
Dim newJSON As newJSON = JsonSerializer.Deserialize(Of newJSON)(json)
For Each feature As Feature In newJSON.features
Dim coordinates As List(Of List(Of Decimal())) = feature.geometry.coordinates
For Each coordinate As List(Of Decimal()) In coordinates
For Each d As Decimal() In coordinate
d(0) = Decimal.Round(Decimal.Parse(d(0)), maxLength)
d(1) = Decimal.Round(Decimal.Parse(d(1)), maxLength)
Next
Next
Next
Dim fileName As String = Path.GetFileNameWithoutExtension(strFile)
fileName = Path.Combine(Path.GetDirectoryName(strFile), fileName + "-compressed.json")
json = JsonSerializer.Serialize(newJSON)
File.WriteAllText(fileName, json)
Next
End Sub