Is it possible to link elements from two jsons, with both jsons embeded ?

0 votes
asked Feb 19 in Wanted features by CuriousC

For a diagram like this  is it possible to connect the two name fields with a link ?

1 Answer

0 votes
answered Feb 21 by Martin (8,320 points)

No, sub-diagrams in Plantuml have to be self-contained and independent of the diagram they are embedded in, whether they be Json or any other diagram type.

It would  be really neat if Plantuml introduced an actual JSON shape, so that you could write something like:

@startuml
component c1 {
json A [
{
"name": "component c1",
"color": ["normal", "green", "red"],
"visible": true
}]}

file f1 {
json B [
{"name": "file f1",
"color": "normal"}
]
}
A::name -> B::name
@enduml

And for it to look something like this (simulated using map objects):

commented Feb 21 by Martin (8,320 points)
edited Feb 21 by Martin

To expand on my idea above.  'json json_name [json_text]' would be a deployment diagram shape
But to allow users to 'roll their own' there could also be a container version 'json json_name { shapes }'. This would just be a rectangle that can style independently.  And a simple json_element element_name [json_text] shape.  json_element  would draw the top-level (object/array/string) of its json parameter text without recursing any deeper. 
The json shape could implicitly (or explicitly) convert itself into a json container by recursing its json parameter text.
eg

json A [
{ "name": "component c1",
"color": ["normal", "green", "red"],
"visible": true }
]
json A {
note: test
}

could be equivalent to/expand to:

json A {
  note: test
  json_element A [
    {
    "name": "component c1",
    "color": ["normal", "green", "red"], 'array contents not recursed, as only the top level json element is drawn
    "visible": true
    }]
  json_element A["colour"] [
    ["normal", "green", "red"]
  ]
  A::A -> A::A["colour"]
}

The above seems feasible to me.  But the biggest problem I foresee is that a deployment diagram would almost certainly lay out the json differently to the existing json diagram, which might confuse/annoy users.

commented Feb 27 by CuriousC
got it thank you
hope they listen to your request :-)
commented Mar 1 by plantuml (279,680 points)

We like the idea, although it might be indeed confusing for users.

So in last beta, you can now have:

@startuml
map CapitalCity {
 UK => London
 USA => Washington
 Germany => Berlin
}

json A {
"name": "component c1",
"color": ["normal", "green", "red"],
"visible": true,
"user" : { "age": 23, "name": "John"}
}
@enduml

This is only working for class and diagram objects.

This is really a beta, and the parser will probably get confuse with complex object.

Is this a good start? Is this what you were expecting?

commented Mar 2 by Martin (8,320 points)

Interesting and clever.  It isn't quite what I was picturing. 
But that's not to say it isn't as good/better.
Let me start by describing better what I was picturing. 

I was picturing that the new json shape would use its json parameter text to draw a single box from Plantuml's standard json diagram, in the same style,  e.g.

json shapeid [ { "A":"X", "B":"Y", "C":[] } ]
would draw the standalone shape of:

It would even draw the dot for the sub-element, but has nowhere to link it to - as it is drawing a single shape and not a full json diagram.
Then I was hoping you could use the ports on such an object as the start/end for arrows.  So there would be some kind of syntax like shapeid::"C" or shapeid["C"] that would let you reference the black dot as a start point for an arrow.
You could then build your own json diagram using these shapes plus arrows.  But crucially you could also mix with deployment shapes and syntax.  I was going for maximum flexibility.  

What you've come up with is a lot more compact and self-contained.
It doesn't give the OP his requirement of adding arbitrary arrows to a json diagram.
It is effectively an alternative to embedding a json sub-diagram into a rectangle - but smaller.  
But it does look useful for people who want to, say, embed a json configuration file in their flow diagram - potentially easier to read than a diagram with lots of boxes and arrows.
And I can see that it fits nicely in the documentation as just a more complex map object rather than something totally new.  (I think part of my problem is I see Plantuml as one big swiss-army-knife and am itching for all the diagram types to unify together.  But I accept this is controversial).  And it fits Plantuml's mission of visualising complex things with minimal manual input, whereas my idea was a lot more manually orientated.
So if this is the end result of my ideas above, then I'm happy I've helped add something potentially useful (although the proof is in whether people use it or not).  Thank you!

PS I tried adding an array of numbers to your example, but the grid lines don't extend far enough:

commented May 30 by The-Lu (49,840 points)
edited May 30 by The-Lu

Hello PlantUML team,

Here is another observed issue, compare:

CodeOutput
@startuml
json J {
  "phoneNumbers": [
    {
      "type": "home",
      "number": "212 555-1234"
    },
    {
      "type": "office",
      "number": "646 555-4567"
    }]
}
@enduml
@startuml
json J {
  "phoneNumbers": [
    {
      "type": "home",
      "number": "212 555-1234"
    },
    {
      "type": "office",
      "number": "646 555-4567"
    }
  ]
}
@enduml
@startuml
json J {
  "phoneNumbers": [
    {"type": "home", "number": "212 555-1234"},
    {"type": "office", "number": "646 555-4567"}
  ]
}
@enduml

Thanks for your works.
Regards.

commented Jun 6 by plantuml (279,680 points)
Thanks for the report, this should be fixed now.

Happy testing! :-)
commented Aug 23 by valexiev (1,180 points)

Hi! I make diagrams of RDF data using PlantUML, and I want to represent rdf:List as a horizontal box with N dots inside, and arrows leading to the list elements. See https://github.com/VladimirAlexiev/rdf2rml/issues/11 where there are illustrations of:

  • PlantUML standalone JSON/YAML
  • Graphviz dot "record-based nodes"
  • PlantUML JSON embedded in class diagram

Unlike JSON standalone, the JSON embedded doesn't show any links, and is therefore limited to displaying trees of data, but not graphs. So currently I don't see any way to do this with PlantUML. I could do it with Graphviz dot (or with https://plantuml.com/dot) but I can't afford to rework (downgrade) my tool to use dot instead of PlantUML.

@Martin, what are "map objects"?

commented Aug 28 by The-Lu (49,840 points)

Hello V., and all,

what are "map objects"?

Here is an example:

map mapObject {
 UK => London
 USA => Washington
 Germany => Berlin
}

See also doc. on Object doc page:

If that can help,
Regards.

asked 1 day ago in Wanted features by The-Lu (49,840 points) [Style] Allow [all] style for JSON object
...