A
A
Arseniy2014-05-22 12:36:12
JSON
Arseniy, 2014-05-22 12:36:12

How to convert JSON to UML using C#?

I really want to try to create an application that, like MySQL WorckBench, would build a query execution plan graphically. The input is just the same plan in JSON format.
The problem is, this code is always dynamic, it is scaled from the type of the select query, for example:

{
  "query_block": {
    "select_id": 1,
    "table": {
      "table_name": "totalprice",
      "access_type": "ALL",
      "rows": 1,
      "filtered": 100
    }
  }
}

or
{
  "query_block": {
    "select_id": 1,
    "grouping_operation": {
      "using_temporary_table": true,
      "using_filesort": true,
      "nested_loop": [
        {
          "table": {
            "table_name": "film",
            "access_type": "range",
            "possible_keys": [
              "PRIMARY",
              "idx_title"
            ],
            "key": "idx_title",
            "used_key_parts": [
              "title"
            ],
            "key_length": "767",
            "rows": 43,
            "filtered": 100,
            "using_index": true,
            "attached_condition": "(`sakila`.`film`.`title` like 'W%')"
          }
        },
        {
          "table": {
            "table_name": "inventory",
            "access_type": "ref",
            "possible_keys": [
              "PRIMARY",
              "idx_fk_film_id"
            ],
            "key": "idx_fk_film_id",
            "used_key_parts": [
              "film_id"
            ],
            "key_length": "2",
            "ref": [
              "sakila.film.film_id"
            ],
            "rows": 2,
            "filtered": 100,
            "using_index": true
          }
...

That is, as I understand it, it will not work to deserialize such JSON using the DataContractJsonSerializer, because I do not know the class structure in advance. You can try to do it dynamically, with JsonConvert.DeserializeObject, for example, and get something like dynamic or Dictonary, but it all seems too confusing.
Question: Is there a simpler way to convert dynamic JSON into something similar to an uml diagram inside the code, i.e. through some libraries?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
snuffi, 2014-09-11
@snuffi

here is a nice library json.codeplex.com
its api: james.newtonking.com/json/help/index.html usage
example:
Product product = new Product();
product.ExpiryDate = new DateTime(2008, 12, 28);
JsonSerializer serializer = new JsonSerializer();
serializer.Converters.Add(new JavaScriptDateTimeConverter());
serializer.NullValueHandling = NullValueHandling.Ignore;
using (StreamWriter sw = new StreamWriter(@"c:\json.txt"))
using (JsonWriter writer = new JsonTextWriter(sw))
{
serializer.Serialize(writer, product);
// {"ExpiryDate":new Date(1230375600000),"Price":0}
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question