JSON sample to [DataContract]
Asked Answered
H

2

5

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.

Hiroshige answered 28/10, 2011 at 18:20 Comment(2)
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
L
6

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.

Loggins answered 28/10, 2011 at 18:31 Comment(1)
Perfect! That's exactly what I wanted. It's not perfect but theres source code to fix the dirty stuff.Hiroshige
S
9

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".

Salubrious answered 2/7, 2015 at 10:26 Comment(0)
L
6

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.

Loggins answered 28/10, 2011 at 18:31 Comment(1)
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.