Home

Awesome

Build and Test codecov

GeoJSON.Text

GeoJSON.Text is a .NET library for the RFC 7946 The GeoJSON Format and it uses and provides System.Text.Json converters for serialization and deserialization of GeoJSON data.

Installation & Usage

GeoJSON.Text NuGet package:

Install-Package GeoJSON.Text

Serialization

Position position = new Position(51.899523, -2.124156);
Point point = new Point(position);

string json = JsonSerializer.Serialize(point);

Deserialization

string json = "{\"coordinates\":[-2.124156,51.899523],\"type\":\"Point\"}";

Point point = JsonSerializer.Deserialize<Point>(json);

See the Tests for more examples.

Special considerations for Newtonsoft.Json

GeoJSON.Text is made to support System.Text.Json, and does not support serializing or deserializing GeoJSON models using Newtonsoft.Json.

If Newtonsoft.Json support is needed, please use GeoJSON.Net.

GeoJSON.Text vs. GeoJSON.NET

This project uses the System.Text.Json serializers, which has become the default and recommended serializers in .NET Core 3.1+.

Benchmarks shows that serializing and deserializing using System.Text.Json is approximately 100% quicker then Newtonsoft.Json and result in 75% less memory allocation when deserializing and 50% less memory allocation when serializing.

<details> <summary>Benchmarks</summary>

Serializing comparison


BenchmarkDotNet=v0.13.1, OS=Windows 10.0.19042.1415 (20H2/October2020Update)
Intel Core i7-9850H CPU 2.60GHz, 1 CPU, 12 logical and 6 physical cores
.NET SDK=6.0.100
  [Host]     : .NET 6.0.0 (6.0.21.52210), X64 RyuJIT
  Job-WNYOAA : .NET 6.0.0 (6.0.21.52210), X64 RyuJIT
  Job-AAKTUU : .NET 5.0.13 (5.0.1321.56516), X64 RyuJIT
  Job-AEYDDU : .NET Core 3.1.22 (CoreCLR 4.700.21.56803, CoreFX 4.700.21.57101), X64 RyuJIT

IterationCount=15  LaunchCount=2  WarmupCount=10  

MethodJobRuntimeToolchainNMeanErrorStdDevRatioRatioSDRankGen 0Gen 1Gen 2Allocated
SerializeSystemTextJsonJob-WNYOAA.NET 6.0net60100000167.3 ms7.28 ms10.44 ms1.000.00I2000.0000--35 MB
SerializeSystemTextJsonJob-AAKTUU.NET 5.0net50100000188.0 ms5.44 ms7.80 ms??I2000.0000--65 MB
SerializeSystemTextJsonJob-AEYDDU.NET Core 3.1netcoreapp31100000235.6 ms7.85 ms11.26 ms??I2333.3333333.3333333.333365 MB
SerializeNewtonsoftJob-WNYOAA.NET 6.0net60100000352.3 ms17.33 ms24.86 ms2.110.16II14000.00003000.0000-112 MB
SerializeNewtonsoftJob-AAKTUU.NET 5.0net50100000376.6 ms12.81 ms19.17 ms??II14000.00003000.0000-112 MB
SerializeNewtonsoftJob-AEYDDU.NET Core 3.1netcoreapp31100000429.6 ms7.57 ms10.61 ms??II14000.00003000.0000-112 MB
<p align="center"> <img src="benchmarkresult/SerializeFeatureCollectionLinestring-barplot.png" width="750" title="Serializing comparison"> </p>

Deserializing comparison


BenchmarkDotNet=v0.13.1, OS=Windows 10.0.19042.1415 (20H2/October2020Update)
Intel Core i7-9850H CPU 2.60GHz, 1 CPU, 12 logical and 6 physical cores
.NET SDK=6.0.100
  [Host]     : .NET 6.0.0 (6.0.21.52210), X64 RyuJIT
  Job-WNYOAA : .NET 6.0.0 (6.0.21.52210), X64 RyuJIT
  Job-AAKTUU : .NET 5.0.13 (5.0.1321.56516), X64 RyuJIT
  Job-AEYDDU : .NET Core 3.1.22 (CoreCLR 4.700.21.56803, CoreFX 4.700.21.57101), X64 RyuJIT

IterationCount=15  LaunchCount=2  WarmupCount=10  

MethodJobRuntimeToolchainNMeanErrorStdDevRatioRatioSDRankGen 0Gen 1Gen 2Allocated
DeserializeSystemTextJsonJob-WNYOAA.NET 6.0net60100000719.6 ms38.29 ms57.31 ms1.000.00I32000.000012000.00001000.0000201 MB
DeserializeSystemTextJsonJob-AAKTUU.NET 5.0net50100000787.3 ms22.38 ms32.80 ms??I32000.000012000.00001000.0000201 MB
DeserializeSystemTextJsonJob-AEYDDU.NET Core 3.1netcoreapp31100000894.6 ms25.84 ms37.87 ms??I32000.000012000.00001000.0000200 MB
DeserializeNewtonsoftJob-WNYOAA.NET 6.0net601000001,410.8 ms27.59 ms40.44 ms1.960.13II146000.000037000.00001000.0000870 MB
DeserializeNewtonsoftJob-AAKTUU.NET 5.0net501000001,430.7 ms31.66 ms46.40 ms??II146000.000037000.00001000.0000870 MB
DeserializeNewtonsoftJob-AEYDDU.NET Core 3.1netcoreapp311000001,656.4 ms40.05 ms58.71 ms??II145000.000037000.00001000.0000869 MB
<p align="center"> <img src="benchmarkresult/DeserializeFeatureCollectionLinestring-barplot.png" width="750" title="Deserializing comparison"> </p> </details>

Contributing

Highly welcome! Just fork away and send a pull request. We try and review most pull requests within a couple of days.

Thanks

This library would be NOTHING without its contributors - thanks so much!!

Sponsors

We have the awesome .NET tools from JetBrains.

Resharper

Contributors

This project exists thanks to all the people who contribute. <a href="https://github.com/GeoJSON-Net/GeoJSON.Text/graphs/contributors"><img src="https://opencollective.com/geojson-net/contributors.svg?width=890&button=false" /></a>

Backers

Thank you to all our backers! 🙏 [Become a backer]

<a href="https://opencollective.com/geojson-net#backers" target="_blank"><img src="https://opencollective.com/geojson-net/backers.svg?width=890"></a>

Sponsors

Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [Become a sponsor]

<a href="https://opencollective.com/geojson-net/sponsor/0/website" target="_blank"><img src="https://opencollective.com/geojson-net/sponsor/0/avatar.svg"></a> <a href="https://opencollective.com/geojson-net/sponsor/1/website" target="_blank"><img src="https://opencollective.com/geojson-net/sponsor/1/avatar.svg"></a> <a href="https://opencollective.com/geojson-net/sponsor/2/website" target="_blank"><img src="https://opencollective.com/geojson-net/sponsor/2/avatar.svg"></a> <a href="https://opencollective.com/geojson-net/sponsor/3/website" target="_blank"><img src="https://opencollective.com/geojson-net/sponsor/3/avatar.svg"></a> <a href="https://opencollective.com/geojson-net/sponsor/4/website" target="_blank"><img src="https://opencollective.com/geojson-net/sponsor/4/avatar.svg"></a> <a href="https://opencollective.com/geojson-net/sponsor/5/website" target="_blank"><img src="https://opencollective.com/geojson-net/sponsor/5/avatar.svg"></a> <a href="https://opencollective.com/geojson-net/sponsor/6/website" target="_blank"><img src="https://opencollective.com/geojson-net/sponsor/6/avatar.svg"></a> <a href="https://opencollective.com/geojson-net/sponsor/7/website" target="_blank"><img src="https://opencollective.com/geojson-net/sponsor/7/avatar.svg"></a> <a href="https://opencollective.com/geojson-net/sponsor/8/website" target="_blank"><img src="https://opencollective.com/geojson-net/sponsor/8/avatar.svg"></a> <a href="https://opencollective.com/geojson-net/sponsor/9/website" target="_blank"><img src="https://opencollective.com/geojson-net/sponsor/9/avatar.svg"></a>