Use PlantUML to display JSON Data

这篇具有很好参考价值的文章主要介绍了Use PlantUML to display JSON Data。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

Display JSON Data

JSON format is widely used in software.

You can use PlantUML to visualize your data.

To activate this feature, the diagram must:

  • begin with @startjson keyword
  • end with @endjson keyword.
@startjson
{
   "fruit":"Apple",
   "size":"Large",
   "color": ["Red", "Green"]
}
@endjson

Use PlantUML to display JSON Data,杂谈,Architect架构,json,UML

Complex example

You can use complex JSON structure.

@startjson
{
  "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
}
@endjson

Use PlantUML to display JSON Data,杂谈,Architect架构,json,UML

Highlight

@startjson
#highlight "lastName"
#highlight "address" / "city"
#highlight "phoneNumbers" / "0" / "number"
{
  "firstName": "John",
  "lastName": "Smith",
  "isAlive": true,
  "age": 28,
  "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
}
@endjson

Use PlantUML to display JSON Data,杂谈,Architect架构,json,UML

Using different styles for highlight

It is possible to have different styles for different highlights.

@startjson
<style>
  .h1 {
    BackGroundColor green
    FontColor white
    FontStyle italic
  }
  .h2 {
    BackGroundColor red
    FontColor white
    FontStyle bold
  }
</style>
#highlight "lastName"
#highlight "address" / "city" <<h1>>
#highlight "phoneNumbers" / "0" / "number" <<h2>>
{
  "firstName": "John",
  "lastName": "Smith",
  "isAlive": true,
  "age": 28,
  "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
}
@endjson

Use PlantUML to display JSON Data,杂谈,Architect架构,json,UML

JSON basic element

Synthesis of all JSON basic element

@startjson
{
"null": null,
"true": true,
"false": false,
"JSON_Number": [-1, -1.1, "<color:green>TBC"],
"JSON_String": "a\nb\rc\td <color:green>TBC...",
"JSON_Object": {
  "{}": {},
  "k_int": 123,
  "k_str": "abc",
  "k_obj": {"k": "v"}
},
"JSON_Array" : [
  [],
  [true, false],
  [-1, 1],
  ["a", "b", "c"],
  ["mix", null, true, 1, {"k": "v"}]
]
}
@endjson

Use PlantUML to display JSON Data,杂谈,Architect架构,json,UML

JSON array or table

Array type

@startjson
{
"Numeric": [1, 2, 3],
"String ": ["v1a", "v2b", "v3c"],
"Boolean": [true, false, true]
}
@endjson

Use PlantUML to display JSON Data,杂谈,Architect架构,json,UML

Minimal array or table

Number array
@startjson
[1, 2, 3]
@endjson

Use PlantUML to display JSON Data,杂谈,Architect架构,json,UML

String array
@startjson
["1a", "2b", "3c"]
@endjson

Use PlantUML to display JSON Data,杂谈,Architect架构,json,UML

Boolean array
@startjson
[true, false, true]
@endjson

Use PlantUML to display JSON Data,杂谈,Architect架构,json,UML

JSON numbers

@startjson
{
"DecimalNumber": [-1, 0, 1],
"DecimalNumber . Digits": [-1.1, 0.1, 1.1],
"DecimalNumber ExponentPart": [1E5]
}
@endjson

Use PlantUML to display JSON Data,杂谈,Architect架构,json,UML

JSON strings

JSON Unicode

On JSON you can use Unicode directly or by using escaped form like \uXXXX.

@startjson
{
  "<color:blue><b>code": "<color:blue><b>value",
  "a\\u005Cb":           "a\u005Cb",
  "\\uD83D\\uDE10":      "\uD83D\uDE10",
  "😐":                  "😐"
}
@endjson

Use PlantUML to display JSON Data,杂谈,Architect架构,json,UML

JSON two-character escape sequence

@startjson
{
 "**legend**: character name":               ["**two-character escape sequence**", "example (between 'a' and 'b')"],
 "quotation mark character (U+0022)":        ["\\\"", "a\"b"],
 "reverse solidus character (U+005C)":       ["\\\\", "a\\b"],
 "solidus character (U+002F)":               ["\\\/", "a\/b"],
 "backspace character (U+0008)":             ["\\b", "a\bb"],
 "form feed character (U+000C)":             ["\\f", "a\fb"],
 "line feed character (U+000A)":             ["\\n", "a\nb"],
 "carriage return character (U+000D)":       ["\\r", "a\rb"],
 "character tabulation character (U+0009)":  ["\\t", "a\tb"]
}
@endjson

Use PlantUML to display JSON Data,杂谈,Architect架构,json,UML

FIXME

 FIXME or not 😉, on the same item as \n management in PlantUML 😉 See Report Bug on QA-13066

FIXME

@startjson
[
"\\\\",
"\\n",
"\\r",
"\\t"
]
@endjson

Use PlantUML to display JSON Data,杂谈,Architect架构,json,UML

Minimal JSON examples

@startjson
"Hello world!"
@endjson

Use PlantUML to display JSON Data,杂谈,Architect架构,json,UML

@startjson
42
@endjson

Use PlantUML to display JSON Data,杂谈,Architect架构,json,UML

@startjson
true
@endjson

Use PlantUML to display JSON Data,杂谈,Architect架构,json,UML

(Examples come from STD 90 - Examples)

Empty table or list

@startjson
{
  "empty_tab": [],
  "empty_list": {}
}
@endjson

Use PlantUML to display JSON Data,杂谈,Architect架构,json,UML

[Ref. QA-14397]

Using (global) style

Without style (by default)

@startjson
#highlight "1" / "hr"
[
  {
    "name": "Mark McGwire",
    "hr":   65,
    "avg":  0.278
  },
  {
    "name": "Sammy Sosa",
    "hr":   63,
    "avg":  0.288
  }
]
@endjson

Use PlantUML to display JSON Data,杂谈,Architect架构,json,UML

With style

You can use style to change rendering of elements.

@startjson
<style>
jsonDiagram {
  node {
    BackGroundColor Khaki
    LineColor lightblue
    FontName Helvetica
    FontColor red
    FontSize 18
    FontStyle bold
    RoundCorner 0
    LineThickness 2
    LineStyle 10-5
    separator {
      LineThickness 0.5
      LineColor black
      LineStyle 1-5
    }
  }
  arrow {
    BackGroundColor lightblue
    LineColor green
    LineThickness 2
    LineStyle 2-5
  }
  highlight {
    BackGroundColor red
    FontColor white
    FontStyle italic
  }
}
</style>
#highlight "1" / "hr"
[
  {
    "name": "Mark McGwire",
    "hr":   65,
    "avg":  0.278
  },
  {
    "name": "Sammy Sosa",
    "hr":   63,
    "avg":  0.288
  }
]
@endjson

Use PlantUML to display JSON Data,杂谈,Architect架构,json,UML

[Adapted from QA-13123 and QA-13288]

Display JSON Data on Class or Object diagram

Simple example

@startuml
class Class
object Object
json JSON {
   "fruit":"Apple",
   "size":"Large",
   "color": ["Red", "Green"]
}
@enduml

Use PlantUML to display JSON Data,杂谈,Architect架构,json,UML

[Ref. QA-15481]

Complex example: with all JSON basic element

@startuml
json "<b>JSON basic element" as J {
"null": null,
"true": true,
"false": false,
"JSON_Number": [-1, -1.1, "<color:green>TBC"],
"JSON_String": "a\nb\rc\td <color:green>TBC...",
"JSON_Object": {
  "{}": {},
  "k_int": 123,
  "k_str": "abc",
  "k_obj": {"k": "v"}
},
"JSON_Array" : [
  [],
  [true, false],
  [-1, 1],
  ["a", "b", "c"],
  ["mix", null, true, 1, {"k": "v"}]
]
}
@enduml

Use PlantUML to display JSON Data,杂谈,Architect架构,json,UML

Display JSON Data on Deployment (Usecase, Component, Deployment) diagram

Simple example

@startuml
allowmixing

component Component
actor     Actor
usecase   Usecase
()        Interface
node      Node
cloud     Cloud

json JSON {
   "fruit":"Apple",
   "size":"Large",
   "color": ["Red", "Green"]
}
@enduml

Use PlantUML to display JSON Data,杂谈,Architect架构,json,UML

[Ref. QA-15481]

Complex example: with arrow

@startuml
allowmixing

agent Agent
stack {
  json "JSON_file.json" as J {
    "fruit":"Apple",
    "size":"Large",
    "color": ["Red", "Green"]
  }
}
database Database

Agent -> J
J -> Database
@enduml

Use PlantUML to display JSON Data,杂谈,Architect架构,json,UML

Display JSON Data on State diagram

Simple example

@startuml
state "A" as stateA
state "C" as stateC {
 state B
}

json J {
   "fruit":"Apple",
   "size":"Large",
   "color": ["Red", "Green"]
}
@enduml

Use PlantUML to display JSON Data,杂谈,Architect架构,json,UML

[Ref. QA-17275]文章来源地址https://www.toymoban.com/news/detail-707434.html

到了这里,关于Use PlantUML to display JSON Data的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • Did not attempt to load JSON data because the request Content-Type was not ‘application/json‘

    在使用flask-restfull进行API开发的时候。一旦我使用类似下面的代码从url或者form中获得参数就会出现报错:Did not attempt to load JSON data because the request Content-Type was not ‘application/json’。 代码如下: 解决方法如下

    2024年02月16日
    浏览(65)
  • 解决运行js代码报错—Warning: To load an ES module, set “type“: “module“ in the package.json or use the .mjs

    目录 ❌ 报错信息 🎈 解决方案 ✔️ 执行结果 vscode运行js代码报错:(node:20452) Warning: To load an ES module, set \\\"type\\\": \\\"module\\\" in the package.json or use the .mjs extension.  同类型报错的情况,都可以使用该方案解决!

    2024年02月08日
    浏览(53)
  • xhost: unable to open display..

    xhost: unable to open display… 在Linux下设置xhost DISPLAY科普 DISPLAY变量是用来设置将图形显示到何处.比如CENTOS,你用图形界面登录进去,DISPLAY自动设置为DISPLAY=:0.0表示显式到本地监视器,那么通过终端工具(例如:xshell)进去,运行图形界面的程序,如果没有设置,系统是不允许程序启动的。

    2024年02月04日
    浏览(47)
  • app.use(express.json()) 使用

    Express内置的中间件 自  Express 4.16.0  版本开始, Express  内置了 3 个常用的中间件,极大的提高了  Express  项目的开发效率和体验 express.static  快速托管静态资源的内置中间件,例如: HTML 文件、图片、 CSS  样式等(无兼容性) express.json  解析  JSON  格式的请求体数据(

    2024年02月13日
    浏览(73)
  • 【杂谈】Unchecked cast: ‘java.lang.Object‘ to ‘T‘ 与单元测试

    一些杂乱的小问题记录 1. Unchecked cast: ‘java.lang.Object’ to ‘T’ 问题描述 有时,我们要自定义一些工具类、工具方法或数据结构,此时需要用到泛型。 我们指导泛型既可以指定类型,也可以作为通配符使用。有时,当我们使用通配符进行类型转换时,IDE会报: 翻译过来就是

    2024年02月04日
    浏览(45)
  • linux下xhost命令报错:unable to open display的解决办法

    linux下执行xhost命令报错:unable to open display,解决方法,linux 下通过xhost进入图形界面,经常会出现报错“unable to open display” linux下的操作步骤如下: 代码如下: 在设置xhost时,出现unable to open display 的问题一般都能用上述方法搞定 输入命令xdpyinfo,记录下里面的name of displ

    2024年02月11日
    浏览(42)
  • Python qt.qpa.xcb: could not connect to display解决办法

    遇到问题:qt.qpa.xcb: could not connect to display 解决办法,在命令行输入: 然后重新跑python程序,解决! 参考博客:qt.qpa.xcb: could not connect to displayqt.qpa.plugin: Could not load the Qt platform plugin \\\"xcb\\\" in \\\"\\\" even though it was found.This application failed to start because no Qt platform plugin could be initialize

    2024年04月28日
    浏览(43)
  • How to Use Glslang

    Execution of Standalone Wrapper 要使用独立的二进制形式,请执行glslang,它将打印一条使用语句。基本操作是给它一个包含着色器的文件,它会打印出警告/错误以及可选的 AST。 应用的特定于阶段的规则基于文件扩展名: vert 顶点着色器 tesc 曲面细分控制着色器 tese 曲面细分评估着

    2024年02月14日
    浏览(37)
  • spring-data-elasticsearch使用Sort排序时Please use a keyword field instead. ……异常解决

    核心提示在 Please use a keyword field instead. Alternatively, set fielddata=true on [dataTimestamp] in order to load field data by uninverting the inverted index. 待排序字段 dataTimestamp 没有为排序优化,所以无法排序,需要配置 FieldType.Keyword 或 fielddata = true ,可是代码中都配置了为什么还提示呢,往下看……

    2023年04月24日
    浏览(41)
  • 解决TortoiseGit软件Git Show log时显示Too many files to display的问题

    有时代码提交修改的文件比较多,当查看log时无法显示出来修改的文件列表,如下所示: 将LogTooManyItemsThreshold尽可能配置得大一些。 https://gitlab.com/tortoisegit/tortoisegit/-/issues/3878

    2024年04月12日
    浏览(39)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包