JsonPropertyPath attribute to enable hoisting nested JSON to a top-level type #107906
Unanswered
hwoodiwiss
asked this question in
Ideas
Replies: 1 comment 1 reply
-
What we do is we have two "Json" types. The "raw" which is exactly what we get from the web service and the "regular" one which is what we reform it to be. In our code that fetches the raw, we immediately transform it so the raw is never actually exposed. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Currently, when provided with a hierarchical JSON payload,
System.Text.Json
provides 2 options for accessing deeply-nested properties within that data:For a given JSON Payload:
Where I've only added the fields, I'm interested in, these approaches can generate a significant amount of boilerplate code or extra types to match the hierarchy.
A useful additions to System.Text.Json would be the ability to use JSON Path as an attribute, and hoist the properties up to a single type. In my opinion this would have great utility in use cases where you are not in control of the JSON you will be receiving, and the JSON you are receiving contains a large number of fields or levels of hierarchy that you do not want or need.
An example usage of what I'm envisioning for the above payload would look like:
Beta Was this translation helpful? Give feedback.
All reactions