terrastruct / d2

D2 is a modern diagram scripting language that turns text to diagrams.
https://d2lang.com
Mozilla Public License 2.0
16.59k stars 417 forks source link

feature: json graph support #1839

Open zrcoder opened 7 months ago

zrcoder commented 7 months ago

It will be great to support rendering json data as graph, like https://plantuml.com/json and https://jsoncrack.com/editor

zrcoder commented 7 months ago

I use sql_table to implement it, see https://github.com/zrcoder/cdor, code like:

package main

import (
    "github.com/zrcoder/cdor"
)

func main() {
    c := cdor.Ctx()
    c.Json(`{
        "firstName": "John",
        "lastName": "Smith",
        "isAlive": true,
        "age": 27,
        "address": {
          "streetAddress": "21 2nd Street",
          "city": "New York",
          "state": "NY",
          "postalCode": "10021-3100"
        },
        "phoneNumbers": [
          {
            "type": "home",
            "number": "212 555-1234"
          },
          {
            "type": "office",
            "number": "646 555-4567"
          }
        ],
        "children": [],
        "spouse": null
      }`)
    c.SaveFile("json.svg")
}

and the renderd svg is like:

json

bo-ku-ra commented 6 months ago

i do something similar with perl script.

dendrogram.txt

firstName: John
lastName: Smith
isAlive: true
age: 27
address
    streetAddress: 21 2nd Street
    city: New York
    state: NY
    postalCode: 10021-3100
phoneNumbers
    type: home
        number: 212 555-1234
    type: office
        number: 646 555-4567
children
spouse: null

↓ dendrogram.pl