title: With C#, is querying YAML possible without defining lots of types?
body: <p>I need to work with YAML generated by Kubernetes and I'd like to be able to read specific properties with an XPath-like or <code>jq</code>-like DSL notation in C#.</p>
  
  <p>The structure and nature of the YAML that Kubernetes generates is well-defined in most places, but in some cases is arbitrary and comes from user input, so it's not possible to define static types up front that can capture the entire structure of the YAML.</p>
  
  <p>The most popular solution for deserializing and reading YAML in C# seems to be <a href="https://github.com/aaubry/YamlDotNet" rel="nofollow noreferrer">YamlDotNet</a>, but it's mostly geared towards deserializing into fully-typed objects.</p>
  
  <p>I'd rather not have to define a bunch of static types or do a lot of cumbersome casting just to get one or two fields or aggregate across them. My ideal approach would instead be something like:</p>
  
  <pre><code>var reader = new FileReader("my-file.yaml");
  List&lt;string&gt; listOfPodNames = Yaml.Deserialize(reader)
                                    .Query(".pods[*].name")
                                    .AsList;
  // expected result: list of all pod names as strings
  </code></pre>
  
  <p>Is this possible with YamlDotNet or another similar and well-supported tool in C#?</p>
  
  <p><strong>Update:</strong> I tried a number of approaches, but in the end, the one that worked best was reserializing to JSON and then querying with Json.NET, which has better support.</p>