1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Filemaker JSONArray

Last updated at Posted at 2025-02-21

FilemakerのJSON関数でもっとも情報が少ないJSONArrayについて覚え書き

基本の配列作成

JSONSetElement ( "{}";
[ "[0]"; "A"; JSONString ];
[ "[1]"; "B"; JSONString ];
[ "[2]"; "C"; JSONString ]
)

結果

["A","B","C"]

要素の追加

Let ( [
	%json =
    	JSONSetElement ( "{}";
    	[ "[0]"; "A"; JSONString ];
    	[ "[1]"; "B"; JSONString ];
    	[ "[2]"; "C"; JSONString ]
    	);
	%json =
    	JSONSetElement ( %json;
    	[ "[3]";	"D";	JSONString ]
    	);
%=0];
    %json
)

結果

["A","B","C","D"]

key付きで配列化

ここでJSONArray登場。もっと良い書き方があればいいのだけれど。

JSONSetElement ( "{}";
[ "data";
	JSONSetElement ( "{}";
    [ "[0]"; "A"; JSONString ];
	[ "[1]"; "B"; JSONString ];
	[ "[2]"; "C"; JSONString ]
	);
	JSONArray ]
)

結果

{"data":["A","B","C"]}

key付きで要素の追加

だんだん面倒くさくなってきました。

Let ( [
	%json =
		JSONSetElement ( "{}";
		[ "data";
			JSONSetElement ( "{}";
			[ "[0]"; "A"; JSONString ];
			[ "[1]"; "B"; JSONString ];
			[ "[2]"; "C"; JSONString ]
			);
			JSONArray ]
		);

	// 配列要素の追加
	%json =
		JSONSetElement ( %json;
		[ "data";
			JSONSetElement ( JSONGetElement ( %json; "data" );
			[ "[3]";	"D";	JSONString ]
			);
			JSONArray ]
		);

%=0];
	%json
)

結果

{"data":["A","B","C","D"]}

key付きに追加する要素の番号を自動で決める

FileMaker 2023なら新機能[+]が使えるけど、古いFileMakerで動作させるための小細工

Let ( [
	%json =
		JSONSetElement ( "{}";
		[ "data";
			JSONSetElement ( "";
			[ "[0]"; "A"; JSONString ];
			[ "[1]"; "B"; JSONString ];
			[ "[2]"; "C"; JSONString ]
			);
			JSONArray ]
		);

	// 配列要素の追加
	%n = ValueCount ( JSONListValues ( %json; "data" ) );
	%json =
		JSONSetElement ( %json;
		[ "data";
			JSONSetElement ( JSONGetElement ( %json; "data" );
			[ "[" & %n + 0 & "]";	"D";	JSONString ];
			[ "[" & %n + 1 & "]";	"E";	JSONString ]
			);
			JSONArray ]
		);

%=0];
	%json
)

結果

{"data":["A","B","C","D","E"]}
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?