I'm trying to convert a xml to json using Json.net
(JsonConvert.SerializeXNode).
There is a problem when you try to convert between an xml and a json if you don't use some kind of schema (xsd), since you can't really identify the difference between an xml collection with a single element to a regular object.
Example:
<Drivers>
<Driver>
<Name>MyName</Name>
</Driver>
</Drivers>
Will be converted into:
"Drivers":{ "Driver": { "Name": "MyName" } }
since nobody tells the serializer that Drivers is a collection with a single object and it thinks it's just a regular object.
Json.net
has a work around for this using the json:Array='true' tagging.
Everything works great when you tag the arrays, but it creates an extra middle object (Driver):
"Drivers": [{"Driver":{"Name": "MyName"}}]
Now I understand why this node is created, but I'm trying to find a way to bypass that creating. I would like to get this result:
"Drivers": [{"Name": "MyName"}]
Does anyone have any idea how to do something like this?