FileMakerカスタム関数 階層構造JSONから目的のキーの値をリストで取得

## 動作検証
FileMaker Pro 19.5.4

# カスタム関数

> `If ( ~children ;` → `If ( not IsEmpty(~children) ;` 修正:2024/02/22

```java:カスタム関数:GetListFromTreeJson ( json ; boolParent ; target ; childrenKey )
While ( 
    [ 
	~json = json;
	~listKey = JSONListKeys ( ~json ; "" );
	~count = ValueCount ( ~listKey ) ; 
	~data = "";
	~n = 1
    ] ; 
    ~n  ≤  ~count ; 
    [
	~data = List(~data ;
			Let(
			~children =  JSONGetElement ( ~json ; "[" & ~n-1 & "]." & childrenKey )
			;
			If ( not IsEmpty(~children) ; 
				List( If( boolParent ; JSONGetElement ( ~json ; "[" & ~n-1 & "]."  & target) ) ; GetListFromTreeJson( ~children ; boolParent ; target ; childrenKey )) ; 
				JSONGetElement ( ~json ; "[" & ~n-1 & "]."  & target) )
			)
		);
        ~n = ~n + 1 
    ] ;
    ~data
)
```
## 階層構造JSON
```json:階層構造JSON
[
    {
        "label": "000.txt",
        "path": "D:\\000\\000.txt"
    },
    {
        "label": "001",
        "path": "D:\\000\\001",
        "children": [
            {
                "label": "001.txt",
                "path": "D:\\000\\001\\001.txt"
            },
            {
                "label": "002",
                "path": "D:\\000\\001\\002",
                "children": [
                    {
                        "label": "002-1.txt",
                        "path": "D:\\000\\001\\002\\002-1.txt"
                    },
                    {
                        "label": "002-2.txt",
                        "path": "D:\\000\\001\\002\\002-2.txt"
                    },
                    {
                        "label": "002.txt",
                        "path": "D:\\000\\001\\002\\002.txt"
                    },
                    {
                        "label": "003",
                        "path": "D:\\000\\001\\002\\003",
                        "children": [
                            {
                                "label": "003.txt",
                                "path": "D:\\000\\001\\002\\003\\003.txt"
                            }
                        ]
                    }
                ]
            }
        ]
    },
    {
        "label": "001-1",
        "path": "D:\\000\\001-1",
        "children": [
            {
                "label": "001-1.txt",
                "path": "D:\\000\\001-1\\001-1.txt"
            }
        ]
    }
]
```


## 使用方法
### 例1
```:式
Let([
json = FileExplorer::treeData
;boolParent = 0
;target = "path"
;childrenKey = "children"
];
GetListFromTreeJson ( json ; boolParent ; target ; childrenKey )
)
```


```:結果
D:\000\000.txt
D:\000\001\001.txt
D:\000\001\002\002-1.txt
D:\000\001\002\002-2.txt
D:\000\001\002\002.txt
D:\000\001\002\003\003.txt
D:\000\001-1\001-1.txt
```

### 例2
```:式
Let([
json = FileExplorer::treeData
;boolParent = 0
;target = "label"
;childrenKey = "children"
];
GetListFromTreeJson ( json ; boolParent ; target ; childrenKey )
)
```


```:結果
000.txt
001.txt
002-1.txt
002-2.txt
002.txt
003.txt
001-1.txt
```


### 例3

##### 親も取得

```:式
Let([
json = FileExplorer::treeData
;boolParent = 1
;target = "path"
;childrenKey = "children"
];
GetListFromTreeJson ( json ; boolParent ; target ; childrenKey )
)
```

```:結果
D:\000\000.txt
D:\000\001
D:\000\001\001.txt
D:\000\001\002
D:\000\001\002\002-1.txt
D:\000\001\002\002-2.txt
D:\000\001\002\002.txt
D:\000\001\002\003
D:\000\001\002\003\003.txt
D:\000\001-1
D:\000\001-1\001-1.txt
```