New! Render PlantUML diagrams directly inside GitHub
with our official browser extension —
No server. No tokens. No tracking. Zero permissions but clipboard. —
Try it out and let us know what you think!
JSON前処理
PlantUMLには、いくつかのJSON前処理機能が搭載されており、すべてのダイアグラムで利用できます。 これは、既存の前処理機能を拡張します。 🛈 JSONデータを表示する方法を探している場合は、「JSONデータを表示する」を確認してください。
変数定義
既存の型(StringとInteger)に加えて、JSON型の変数を定義できます。
例:
!$foo = { "name": "John", "age" : 30 }
これは、次のような構造に対応します:
WARNING
This translation need to be updated. WARNING
データへのアクセス
変数を定義すると、そのメンバにアクセスすることができます:
WARNING
This translation need to be updated. WARNING
複雑な構造
複数行にわたる、複雑なJSONオブジェクトや配列を定義することもできます。
$fooを定義します:
$foo.employees[0].name$foo.employees[0].salary
!$attribute_1="name"!$attribute_2="salary"
$foo.employees[0][$attribute_1]$foo.employees[0][$attribute_2]
データのロード
標準関数を使用して、URLまたはローカルファイルからJSONオブジェクトをロードできます:
!$foo = %load_json("http://foo.net/users/list.json")
!$foo2 = %load_json("myDir/localFile.json")
1.2021.15 以降で利用可能
繰り返し [foreach]
配列を定義すると、それに対してループ処理を行うことができます。
- for or better foreach ? ->
foreach - It would be nice to also have "break" and "continue"
- It would be nice to also have the for or while loop with a standard variable
[SW] Some remarks
- for or better foreach ? ->
foreach- It would be nice to also have "break" and "continue"
- It would be nice to also have the for or while loop with a standard variable
WARNING
This translation need to be updated. WARNING
Full Example
From a example worked in a forum question, with this JSON structure:
Self-descriptive example
Here is a self-descriptive example:

%get_json_keys builtin function
You can use %get_json_keys to get all the keys of one level on a JSON structure.

%get_json_type builtin function
You can use %get_json_type to get the type of an element of a JSON structure (returns a string).

%json_key_exists builtin function
You can use %json_key_exists to know if a key exists on a JSON structure (returns a boolean).

%size builtin function
You can use %size to know the size of different elements on a JSON structure.
For each type here are the return value:
| Type | Return value |
JSON Object
|
the number of pairs it contains |
JSON Array
|
the number of values it contains |
string value
|
the number of characters it contains |
numeric value
|
zero |
true/false/null
|
zero |

%json_add builtin function
You can use %json_add to add element on an existing JSON structure (returns the final JSON structure).

%json_remove builtin function
You can use %json_remove to remove element on an existing JSON structure (returns the final JSON structure).

%json_set builtin function
You can use %json_set to set element on an existing JSON structure (returns the final JSON structure).

%json_merge builtin function
You can use %json_merge to merge JSON structures (returns the final JSON structure).

%str2json builtin function
You can use %str2json to transform a string value to a JSON structure.
Here are some example:
🚩 Known issue: Unfortunately, be careful with quote management. Some issues occur when a single quote is contained in a string when the entire string is surrounded by single quote.[Ref. PR-1742]