© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•6mo ago•
9 replies
VoidPointer

Deserialize JSON With Dynamic Properties

I'm trying to build a deserializer for GCP log entries, and they all seem to have the same basic structure, and it looks like our own log info gets stored in the
textPayload
textPayload
property of the JSON of a log entry, but that's not really relevant.

My problem is many different entries have different structures for their
labels
labels
properties. For example, one entry will have labels like this:
{
  "textPayload": "xxx",
  "timestamp": "xxx",
  "severity": "DEBUG",
  "labels": {
    "python_logger": "xxx",
    "environment": "xxx",
    "hostInstance": "xxx"
  },
  "logName": "xxx",
}
{
  "textPayload": "xxx",
  "timestamp": "xxx",
  "severity": "DEBUG",
  "labels": {
    "python_logger": "xxx",
    "environment": "xxx",
    "hostInstance": "xxx"
  },
  "logName": "xxx",
}

and another entry will have labels like this:
{
  "textPayload": "xxx",
  "timestamp": "xxx",
  "severity": "DEBUG",
  "labels": {
    "api-id": "xxx",
    "start-datetime": "xxx",
    "Session": "xxx",
    "identity-number": "xxx",
    "api-url": "xxx",
    "segment-group-id": "00000000-0000-0000-0000-000000000000",
    "success": "true",
    "kyc-id": "xxx",
    "latency": "5"
  },
  "logName": "xxx"
}
{
  "textPayload": "xxx",
  "timestamp": "xxx",
  "severity": "DEBUG",
  "labels": {
    "api-id": "xxx",
    "start-datetime": "xxx",
    "Session": "xxx",
    "identity-number": "xxx",
    "api-url": "xxx",
    "segment-group-id": "00000000-0000-0000-0000-000000000000",
    "success": "true",
    "kyc-id": "xxx",
    "latency": "5"
  },
  "logName": "xxx"
}

I've already figured it's probably best to deserialize the
labels
labels
property into a dictionary rather than something vague like
object
object
or daft like
dynamic
dynamic
, but I have no clue on how to go about this.

I have half an idea I must write a converter for the
labels
labels
property, but there are other
labels
labels
properties nested within properties not shown in these examples, so how do I write a converter for only the
labels
labels
property at the root of the log entry json object?

Is a converter even the way to go, or is there an easier way to just deserialize a json property to a to a dictionary, with no real conversions needed?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

✅ Ways to deserialize Json with dynamic model
C#CC# / help
3y ago
Deserialize JSON to dynamic object without Newtonsoft.Json
C#CC# / help
4y ago
JSON Deserialize
C#CC# / help
2y ago
JSON deserialize
C#CC# / help
2y ago