tbone
tbone

Reputation: 5865

Theoretically possible to generate physical database schema from JSON document?

I have a json document (with no accompanying schema, would have to infer from the document) containing several entities with associations, see:
https://msdn.microsoft.com/en-us/library/azure/mt267562.aspx

If I paste that document into http://json2csharp.com/ it seems to be able to do a decent job of inferring the objects and associations.

Considering that, is it theoretically possible to write a utility that could take an existing instance of that json document and create the corresponding database schema (and subsequently import the data) that could hold the data contained within the document, or are there going to be some sort of scenarios that I wouldn't be able to translate (I guess kinda similar to an ORM impedance mismatch)?

Or is there an alternative approach to this that already exists so I'm not reinventing the wheel?

Upvotes: 0

Views: 89

Answers (3)

Francisco d'Anconia
Francisco d'Anconia

Reputation: 2633

That's a really interesting idea. I think you are most of the way there with your two links. I think with using an ORM like EF Code First, you could generate the DB context, then generate the database.

Could you plug in the output from json2csharp into the following code first sample? That would create the context and the database, which is what you're looking for.

https://msdn.microsoft.com/en-us/data/jj193542.aspx

On another note, I'm struggling to see a real-world application for this. When would you have random json that you know nothing about that you'd want to save to a database. And given that, how would you query it again later, and why?

But I'm sure there were people that thought no one would ever use google or an IPhone, so what do I know? :)

Upvotes: 0

Boris Sokolov
Boris Sokolov

Reputation: 1803

You could take a look on this solution on CodeProject

Upvotes: 0

Michael Baker
Michael Baker

Reputation: 3434

If you can you generate C# or at least some classes from the JSON document you can give those classes (entities) to Entity Framework which will give you a database schema automatically.

Upvotes: 1

Related Questions