Created
August 12, 2024 12:15
-
-
Save VisualBean/21a1b12dd946476bbc2ffb164dd74dd1 to your computer and use it in GitHub Desktop.
JsonPointer deserialization example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Json.Pointer; | |
using System.Text.Json; | |
using System.Text.Json.Nodes; | |
var json = | |
""" | |
{ | |
"objects": { | |
"and": { | |
"myProp": "1234" | |
} | |
} | |
} | |
"""; | |
var pointer = JsonPointer.Parse("/objects/and"); | |
var result = JsonNode.Parse(json); | |
if (pointer.TryEvaluate(result, out var pointerResult)) | |
{ | |
var conversionResult = pointerResult.Deserialize<And>(new JsonSerializerOptions { PropertyNameCaseInsensitive = true }); | |
} | |
class And | |
{ | |
public string MyProp { get; set; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment