How cal be aligned to the left the generated from a JSON file

0 votes
asked Feb 8, 2021 in Question / help by oscaretu (180 points)
Hello.

When PlantUML renders a JSON file, the column for the field names appears centered, and I want it to be left aligned. How can I get it?
commented Feb 8, 2021 by The-Lu (64,340 points)

Hello O. and all,

Just FYI, see similar request here:

Regards,
Th.

commented Feb 8, 2021 by Martin (8,360 points)
edited Feb 8, 2021 by Martin

I think this is a wanted feature, and I'm sure Plantuml would appreciate syntax suggestions.

e.g. (for debate)

<style> jsonDiagram { ObjectName { HorizontalAlignment left } } </style>

<style> yamlDiagram { MappingKey { HorizontalAlignment left } } </style>

per field ideas:

<style> jsonDiagram { ObjectName { :"lastName" { HorizontalAlignment left } } } </style>

#NameHorizontalAlignment "lastName" left

"<align:left>lastName": "<color:blue><b>value"

note:  #Highlight syntax already supports nested fields (see https://forum.plantuml.net/12532/how-to-hihlight-array-item-in-json-data) e.g. 

#highlight "phoneNumbers" / "1" / "number"

1 Answer

0 votes
answered Feb 16, 2021 by Martin (8,360 points)

This has been changed

The default is now that the field names are left aligned:

@startjson
{
   "very long fruit":"Big piece of Apple",
   "size":"Large",
   "color":"Red"
}
@endjson

But the alignment can be changed using Style:

@startjson
<style>
  jsonDiagram {
    HorizontalAlignment Center
  }
</style>
{
   "very long fruit":"Big piece of Apple",
   "size":"Large",
   "color":"Red"
}
@endjson

See this answer for more new style options.

commented Feb 16, 2021 by oscaretu (180 points)

This doesn't work for me using the last downloadable version... I've checked whether there is a newer version that changes the default behaviour, but the one available in https://plantuml.com/es/download is the same one I downloaded some days ago:

oscar@toreyes$ java -jar plantuml.jar -version
PlantUML version 1.2021.01 (Tue Feb 02 08:55:08 CET 2021)
(GPL source distribution)
Java Runtime: OpenJDK Runtime Environment
JVM: OpenJDK 64-Bit Server VM
Default Encoding: UTF-8
Language: es
Country: ES

PLANTUML_LIMIT_SIZE: 4096

Dot version: dot - graphviz version 2.38.0 (20140413.2041)
Installation seems OK. File generation OK

I've tried to add the style information to my file, putting Left instead of Center:

<style>
  jsonDiagram {
    HorizontalAlignment Left
  }
</style>

but it gives an error: Your data doesn't sound as JSON data.

In the next URL

http://www.plantuml.com/plantuml/umla/jLThJ_Cs6FsUN-5b7v2gbOOC65GmqOrfPEAYQJ3jeiboawUf8R63xVG2wdzVqX1UzxKRQ0EFK57hSquUdzW-yfbKHAXxoPdZxEoWRpQe4dyxfX9DkNYGY8xGdET8GCedWDGOq8bKymH-H0bbiB6uKxFBtiufYGL9qJEwu88-SQP8CaXep59W2lrSV8102tJIgpYEy-sOnkC2C5R8PLpH4Gs9efnXDS_0NHa6Dg62BvLM1t9Mq2320aAWsHk3g8VSX2YGglu9KpRYsv7AtxqsrFAJ2nfJHXAi166IXClfqyXrd6S75UMINF62p62ACy6ZF5JbCEeZTy__Vl_WqFtEm4b5L2vTL5Q1KoA76ZKikMOLg92dkxFPRFUfg5VqH4ZNYZxQFwf1-fjP1NKwVn0M3Vciqwd1gsQu6XYc_BU0NMV_-0VZwEBFURSeDEH2a8YZRbdHNrSqEFVYu7v0RwRPiLMpDhZKh1nicdVp_2qUD7jH-J7Bg0298wB091elpk3W4HSfKGeYtHxVyxskTzprVRHtsFT_w7jxw1SLzdwzkdrR26TIkQQGT_mYD4X1q93qBhd40nP30b8NfH9JLlmfmJ4VZK3WhC3pkhz2T4GI2LzHbA0aqP1wMIaAKamDQ8Dlskx9SX6EYGJDTQjlVj_Rj_bc5yAfT3TzU8FNvSERlLv_7ZIve9yBxtNERXXgTCwwuko6DJ_SQbXTTkVUNgMFEM6AghcxVlteS9aFPIXejZGu5ZpF2l-0bI44mhNtRNydpNFD6NtCGTUsSxfhgHDW4HUwWfLg_3Fq9Y1asJhC50X64bsoqlDq-1I6c8i814ue0rplJtEsIygYObfol8g2u3gu3GQN-AUxlx_4GKQad78HkMjDD3BLEDgj-LEel6JFYumrVMheLH3qqfluoJSov-xWuVVJKqt3dZPzz6-9g4jhRuDOQ3pYcmMDVMVwQEUQ-s_hc6WH5orYuyEZe4qaV6eqj8c8Db7nuP7H9Ze-DKAsZ98saT8cMhOygEjQl7xxJuzcO15bSNMJ8CdxppVxFQMfzOPRIyNQQF5llkmtzgRki8yyfq8j7CSv0nQLjz__0G00

it works (in the online version) when you remove the <style> line.

commented Feb 17, 2021 by Martin (8,360 points)

Plantuml can be a bit fussy about having certain newlines in place.  Your online example works if you separate out the style lines a bit:

<style> 
jsonDiagram { 
  HorizontalAlignment Center 

</style>

For local, you might need the beta version for the time being: http://beta.plantuml.net/plantuml.jar (1.2021.2beta8)

commented Feb 17, 2021 by oscaretu (180 points)

Thanks a lot for your help, Martin.

Using beta version I can get PNG and SVG, but PDF fails:

oscar@toreyesxps$ java -jar plantuml-1.2021.2beta8.jar -tpdf notificacion_numero_01_INITIAL_BUY.puml
Exception in thread "main" java.lang.UnsupportedOperationException: PDF
        at net.sourceforge.plantuml.ugraphic.ImageBuilder.createUGraphic(ImageBuilder.java:307)
        at net.sourceforge.plantuml.ugraphic.ImageBuilder.writeImageInternal(ImageBuilder.java:145)
        at net.sourceforge.plantuml.ugraphic.ImageBuilder.writeImageTOBEMOVED(ImageBuilder.java:129)
        at net.sourceforge.plantuml.jsondiagram.JsonDiagram.exportDiagramNow(JsonDiagram.java:121)
        at net.sourceforge.plantuml.AbstractPSystem.exportDiagram(AbstractPSystem.java:145)
        at net.sourceforge.plantuml.PSystemUtils.exportDiagramsDefault(PSystemUtils.java:154)
        at net.sourceforge.plantuml.PSystemUtils.exportDiagrams(PSystemUtils.java:97)
        at net.sourceforge.plantuml.SourceFileReaderAbstract.getGeneratedImages(SourceFileReaderAbstract.java:160)
        at net.sourceforge.plantuml.Run.manageFileInternal(Run.java:536)
        at net.sourceforge.plantuml.Run.processArgs(Run.java:420)
        at net.sourceforge.plantuml.Run.manageAllFiles(Run.java:387)
        at net.sourceforge.plantuml.Run.main(Run.java:198)

Using the stable version, I can get the PDF (but with centered texts)

commented Feb 17, 2021 by Martin (8,360 points)

I don't use PDF, and I've not got the additional libraries installed to try it.  But if it works with the old jar and not the new beta jar, then it sounds like a regression bug.  I suggest you raise it as new bug - stating that it is on 1.2021.2beta8, to make it more visible.

...