Is there any tool allowing to generate DataContract entity definitions based on a JSON sample? I'm really missing the old good WSDL metadata with code generation facilities.
JSON sample to [DataContract]
Asked Answered
JSON doesn't specify any type information. JSON nested objects that declare the same set of fields might correspond to equivalent classes -- or they might not. When you sacrifice all that meta data by using JSON, you really are sacrificing quite a lot of info, and part of that sacrifice means that it is not possible to robustly generate C# types (i.e. statically-typed) based on JSON (i.e. not dynamically-typed). –
Hiers
Well, you can guess. At least you can differentiate between entities, arrays, integers, and strings. You can try to guess type inside string value sample i.e. TimeSpan looks like "00:00:00" etc. I don't mind fixing entity types after generator but I do mind generating all by hand. –
Hiroshige
Yes, you can find such a tool at http://jsontodatacontract.azurewebsites.net/. There's a post about it at http://blogs.msdn.com/b/carlosfigueira/archive/2011/01/11/inferring-schemas-for-json.aspx.
Perfect! That's exactly what I wanted. It's not perfect but theres source code to fix the dirty stuff. –
Hiroshige
I know this is a very old question but it's worth noting that if you're using Visual Studio you get that without any external tools - you can copy some JSON in your clipboard and then go to Edit > Edit Special > "Paste JSON As Classes".
Yes, you can find such a tool at http://jsontodatacontract.azurewebsites.net/. There's a post about it at http://blogs.msdn.com/b/carlosfigueira/archive/2011/01/11/inferring-schemas-for-json.aspx.
Perfect! That's exactly what I wanted. It's not perfect but theres source code to fix the dirty stuff. –
Hiroshige
© 2022 - 2024 — McMap. All rights reserved.