C#C
C#3y ago
26 replies
Thinker

❔ Parsing JSON value with multiple different possibilities

I have a JSON object which can take on one of two different structures
"name": {
  "first": "John",
  "last": "Smith"
}
// or
"name": "John Smith"

How would I go about parsing this into an object using STJ? Assume the object to deserialize to is this
record Person(Name Name);
record Name(string First, string Last);
Was this page helpful?