I have very large json file with lots of data. Structure looks like this
{
"country": "AD",
"name": "Pas de la Casa",
"lat": "42.54277",
"lng": "1.73361"
},
In my current c# code I have coordinates, let's say
var lat = "42.53";
var lng = "1.74";
Is there some way to read JSON without parsing it completely into memory first as file is pretty big, around 12 Mb. Can somebody provide some code example how this can be done using System.Text.Json.
I understand that I should create a class, like:
public class Location
{
public string Country { get; set; }
public string City { get; set; }
public double Latitude { get; set; }
public double Longitude { get; set; }
}
Then deserialize it?
Location location =
JsonSerializer.Deserialize<Location>(filepath?);
However my question is:
- How to first search for most closely matching coordinates, like in my example they does not completely match, but I need to get the most closest one.
- After match has been found get Country and City out of JSON.