When using the XElement
API and asking for a particular element (via .Element("Foo")
), I get back an object which, when serialized to JSON (using ASP.NET Core), results in an object with a single field (Foo), which then contains all of the child objects of Foo.
How do I make it so that all of the children of Foo are contained in the top level of the serialized object? The .Elements()
method will get me the elements but I don't want them as a collection, I want them as fields on an object.