Blog: JSON

Advanced Newtonsoft.Json: Dynamically rename or ignore properties without changing the serialized class

November 2, 2017, Software Development

This article describes how to implement a custom contract resolver, so that you can ignore or rename serialized JSON properties where the serialization happens and without changing the serialized classes. I use this resolver in my project NSwag, a Swagger/Open API toolchain: A Swagger specification uses JSON Schemas to describe types, but it is not exactly the same model – some properties of a schema are not allowed and some must be renamed. Because I cannot change the JSON Schema implementation, I had to ignore or rename properties in the Swagger serializer. Another use case of this contract resolver is, […] Read more...

Tags: , , ,

Use JSON files with schema for application configuration

September 12, 2014, (updated on February 25, 2017), 2 comments, Software Development

Often, we face the problem that our customers need highly configurable applications but there is no time to develop rich configuration GUIs. This article describes a possible solution which is a compromise between editing raw configuration files and implementing rich configuration GUIs. The idea: First, implement some simple POCO classes (Plain Old CLR Object) representing the structure of the required configuration. Using a JSON serializer these classes can then be written and read from a JSON configuration file. Additionally, store an auto-generated JSON schema file alongside the configuration file. To edit the configuration file after its creation, use the tool […] Read more...

Tags: , , , ,

  Page 1 of 1