Read List

Use data.json.list to read data as java.util.List from JSON file. Passed path is either relative based on working dir or absolute file path. Or it can be a resource class path. Groovy def list = data.json.list("data/flat-list.json") list[0].name.should == "hello" list[1].payload.should == [info: ~/id2 payload/] Check data/import-and-dependencies Import And Dependencies for prerequisites. Java List<Map<String, ?>> list = data.json.list("data/flat-list.json"); actual(list.get(0).get("name")).should(equal("hello")); actual(list.get(1).get("payload")).should( equal(map("info", Pattern.compile("id2 payload")))); Check data/import-and-dependencies Import And Dependencies for prerequisites. read methods produce additional report to help with tests investigation > reading json from file or resource data/flat-list.json . read 16 lines of json from file /home/runner/work/webtau/webtau/webtau-feature-testing/examples/data/flat-list.json (0ms)

Read Map

Use data.json.map to read data as java.util.Map from JSON file. Passed path is either relative based on working dir or absolute path. Or it can be a resource class path. Groovy def map = data.json.map("data/root-map.json") map.payload.should == [info: "additional id1 payload"] Java Map<String, ?> map = data.json.map("data/root-map.json"); actual(map.get("payload")).should(equal(map("info", "additional id1 payload")));

Read TableData

Use data.json.table to read data as TableData from JSON file. JSON must be a list. Passed path is either relative based on working dir or absolute file path. Or it can be a resource class path. Groovy def table = data.json.table("data/flat-list.json") table.should == [ "id" | "name" | "payload"] { _________________________________________ "id1" | "hello" | [info: ~/id1 payload/] "id2" | "world" | [info: ~/id2 payload/] } Java TableData jsonTable = data.json.table("data/flat-list.json"); TableData expected = table("id" , "name" , "payload", ________________________________________________________________, "id1", "hello" , map("info", Pattern.compile("id1 payload")), "id2", "world" , map("info", Pattern.compile("id2 payload"))); actual(jsonTable).should(equal(expected));

Read Object

Use data.json.object to read data as either java.util.List or java.util.Map or a single value from JSON file. Passed path is either relative based on working dir or absolute file path. Or it can be a resource class path. Groovy def object = data.json.object("data/single.json") object.should == "hello world" Java Object object = data.json.object("data/single.json"); actual(object).should(equal("hello world"));

Parse Map

Use data.json.mapFromString to parse given JSON string as java.util.Map Groovy def map = data.json.mapFromString("""{"key": "value"}""") map.should == [key: "value"] Java Map<String, ?> map = data.json.mapFromString("{\"key\": \"value\"})"); actual(map).should(equal(map("key", "value")));

Parse List

Use data.json.listFromString to parse given JSON string as java.util.List Groovy def list = data.json.listFromString("""[{"key1": "value1"}, {"key2": "value2"}]""") list.should == [ [key1: "value1"], [key2: "value2"]] Java List<Map<String, ?>> list = data.json.listFromString("[{\"key1\": \"value1\"}, {\"key2\": \"value2\"}]"); actual(list).should(equal(list( map("key1", "value1"), map("key2", "value2"))));

Parse TableData

Use data.json.tableFromString to parse given JSON string as TableData Groovy def table = data.json.tableFromString(""" [ { "id": "id1", "name": "hello", "payload": { "info": "additional id1 payload" } }, { "id": "id2", "name": "world", "payload": { "info": "additional id2 payload" } } ] """) table.should == [ "id" | "name" | "payload"] { _________________________________________ "id1" | "hello" | [info: ~/id1 payload/] "id2" | "world" | [info: ~/id2 payload/] } Java TableData jsonTable = data.json.tableFromString("[\n" + " {\n" + " \"id\": \"id1\",\n" + " \"name\": \"hello\",\n" + " \"payload\": {\n" + " \"info\": \"additional id1 payload\"\n" + " }\n" + " },\n" + " {\n" + " \"id\": \"id2\",\n" + " \"name\": \"world\",\n" + " \"payload\": {\n" + " \"info\": \"additional id2 payload\"\n" + " }\n" + " }\n" + "]"); TableData expected = table("id" , "name" , "payload", __________________________________________________________________, "id1", "hello" , map("info", Pattern.compile("id1 payload")), "id2", "world" , map("info", Pattern.compile("id2 payload"))); actual(jsonTable).should(equal(expected));

Parse Object

Use data.json.objectFromString to parse given JSON string as either java.util.List or java.util.Map or a single value from JSON file. Groovy def object = data.json.objectFromString("\"hello world\"") object.should == "hello world" Java Object list = data.json.objectFromString("\"hello world\""); actual(list).should(equal("hello world"));

Write List

Use data.json.write to write data to JSON file. Groovy def list = [ ["colA": 1, "colB": "R1"], ["colA": 2, "colB": "R2"]] def path = data.json.write("generated/from-list-maps.json", list) Java List<Map<String, ?>> list = list( map("colA", 1, "colB", "R1"), map("colA", 2, "colB", "R2")); Path path = data.json.write("generated/from-list-maps.json", list); write methods produce additional information that helps with tests investigation > writing json to file generated/from-list-maps.json . wrote 7 lines to json /home/runner/work/webtau/webtau/webtau-feature-testing/examples/generated/from-list-maps.json (0ms) [ { "colA" : 1, "colB" : "R1" }, { "colA" : 2, "colB" : "R2" } ]

Write Map

Groovy def map = ["colA": 1, "colB": "R1"] def path = data.json.write("generated/from-map.json", map) Java Map<String, ?> map = map("colA", 1, "colB", "R1"); Path path = data.json.write("generated/from-list-maps.json", map); { "colA" : 1, "colB" : "R1" }

Write Table Data

Groovy TableData table = ["id" | "value"] { ________________ "id1" | "value1" "id2" | "value2" } def path = data.json.write("generated/from-table-data.json", table) Java TableData csvTable = table("id" , "value", ________________, "id1" , "value1", "id2" , "value2"); Path path = data.json.write("generated/from-table-data.json", csvTable); write methods produce additional information that helps with tests investigation > writing json to file generated/from-table-data.json . wrote 7 lines to json /home/runner/work/webtau/webtau/webtau-feature-testing/examples/generated/from-table-data.json (1ms) [ { "id" : "id1", "value" : "value1" }, { "id" : "id2", "value" : "value2" } ]