Just Simply Code

Another developer blog

  • Home
  • About
  • Register
  • Policy

Json

Get value of a property in JSON string without knowing the strongly type to deserialise to

29 May 2022 / Leave a Comment

In one component of my current project, I need to grab the value of a property by name from a given JSON string. This JSON string is dynamic and I don’t know which strongly typed class to deserialise it to. Below is the function I ended up with to solve this problem.

Posted in: Uncategorised Tagged: .Net Core, Json

Storing complex object property as JSON in SQL using Entity Framework

8 May 2022 / Leave a Comment

I have a class with a complex object property that has a lot of properties and a lot of nested complex properties in it. Other properties in this class will be stored in SQL the normal way, relational and one column per property. Given the complexity of this particular property, I want to store it … [Read more…]

Posted in: Uncategorised Tagged: .Net Core, EF Core, Json, SQL

Custom JSON converter for a class

17 April 2022 / Leave a Comment

I recently have to build a class which has a property of type object. This property can be one of three types based on another property in the same class. Serialising Transaction class is fine and would just work. However, deserialising it would be a problem. For the Account property, it would not know which … [Read more…]

Posted in: Uncategorised Tagged: .Net Core, Json, Json Converter

Custom JSON converter to replace a complex object property with string

27 March 2022 / Leave a Comment

In my recent project, we have an Address class that is complex and has many properties in it. This class also has an ID property. We have a requirement where we need to replace this object with the ID string of the address wherever the address is used in any object when serialising to JSON. … [Read more…]

Posted in: Uncategorised Tagged: .Net Core, Json, Json Converter

JSON deserialisation exception with Enumerable.Empty

21 November 2021 / Leave a Comment

I came across this exception in the past after upgrading .NET Core 2.2 to 3.0. I didn’t write about it before but recently I saw this exception again in our error logs so I thought I’d write about this and how to solve it. If you have a model like this That Enumerable.Empty<Author>() is to … [Read more…]

Posted in: Uncategorised Tagged: .Net Core, Json, Json Deserialisation

Custom JSON converter to de-serialise Enum description value to Enum value

1 August 2021 / Leave a Comment

It’s common to have description attributes on Enum types. This allows adding a longer description string for each Enum value. In one of my recent projects, I have a Web API that needs to accept this description value from the JSON request body and map to the correct Enum value. In this post, I’m going … [Read more…]

Posted in: Uncategorised Tagged: Enum, Json, Json Converter, Json Deserialisation, Json Serialisation

Auto trimming all values when deserialising Json string

1 March 2020 / Leave a Comment

For the project at work, we have these dynamic document forms each has their own model that Json string data posted back from the front end will be deserialised into. We don’t want to manually trim all the properties in each model when we consume them, so we thought we’d add a custom Json converter … [Read more…]

Posted in: Uncategorised Tagged: Json, Json Deserialisation

Comparing Json strings in unit tests

14 September 2019 / Leave a Comment

There are a couple ways to verify if 2 Json strings are equivalent. Using DeepEquals on JObject There’s a static function DeepEquals on JObject which compares the values of 2 tokens and all their descendant tokens. We can parse the Json strings into JObject and then use this function to compare them. Using FluentAssertions Another … [Read more…]

Posted in: Uncategorised Tagged: Json, Unit Test

NullValueHandling.Ignore is ignored when deserialising Json to anonymous object

31 August 2019 / Leave a Comment

In my project at work, I come across a function where I have to deserialise a Json string to an anonymous object. For Json serialisation in this project, we always use the following Json serialisation settings. I expect the result anonymous object would ignore null properties but they are included. See example below This is … [Read more…]

Posted in: Uncategorised Tagged: Json, Json Deserialisation, Json Serialisation

Merging and replacing 2 Json strings

17 August 2019 / Leave a Comment

Recently at work, I have a requirement to merge two json strings. Basically, I want to achieve what the spread operator does in Javascript.For examples, let’s say we have a json string as below. And we want to merge the below json string The result we want to achieve is as followed After some research, … [Read more…]

Posted in: Uncategorised Tagged: Json
1 2 Next »

Search Posts

Recent Posts

  • Override IHttpRequestBodyDetectionFeature.CanHaveBodyOverride value in .NET Core Web API
  • Allow empty request body in PUT and POST HTTP requests in .NET Core Web API
  • Modify request body with middleware in .NET Core Web API
  • Running MS Orleans on AWS ECS
  • Respect leading and trailing spaces when querying SQL Server
Support my blog here!Support my blog!

Archives

  • July 2024
  • June 2024
  • July 2023
  • April 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022
  • August 2022
  • July 2022
  • June 2022
  • May 2022
  • April 2022
  • March 2022
  • February 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • June 2021
  • May 2021
  • April 2021
  • March 2021
  • February 2021
  • January 2021
  • December 2020
  • November 2020
  • October 2020
  • September 2020
  • August 2020
  • July 2020
  • June 2020
  • May 2020
  • April 2020
  • March 2020
  • February 2020
  • January 2020
  • December 2019
  • November 2019
  • October 2019
  • September 2019
  • August 2019
  • July 2019
  • June 2019
  • May 2019
  • April 2019
  • March 2019
  • February 2019
  • January 2019
  • December 2018
  • November 2018
  • October 2018
  • September 2018
  • August 2018
  • July 2018
  • June 2018
  • May 2018
  • October 2017
  • September 2017
  • July 2017
  • June 2017
  • May 2017
  • April 2017
  • March 2017
  • February 2017
  • January 2017
  • December 2016
  • November 2016
  • October 2016
  • September 2016
  • July 2016
  • June 2016
  • March 2016
  • February 2016
  • January 2016

Copyright © 2025 Just Simply Code.

Me WordPress Theme by themehall.com