Skip to content

Commit 6ed0c9a

Browse files
Add sample examples for read function
1 parent 845a854 commit 6ed0c9a

File tree

5 files changed

+46
-7
lines changed

5 files changed

+46
-7
lines changed

.vscode/launch.json

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"configurations": [
3+
{
4+
"name": "Ballerina Debug",
5+
"type": "ballerina",
6+
"request": "launch",
7+
"programArgs": [],
8+
"commandOptions": [],
9+
"env": {}
10+
},
11+
{
12+
"name": "Ballerina Test",
13+
"type": "ballerina",
14+
"request": "launch",
15+
"debugTests": true,
16+
"programArgs": [],
17+
"commandOptions": [],
18+
"env": {}
19+
},
20+
{
21+
"name": "Ballerina Remote",
22+
"type": "ballerina",
23+
"request": "attach",
24+
"debuggeeHost": "127.0.0.1",
25+
"debuggeePort": "5005"
26+
}
27+
]
28+
}

ballerina/read.bal

+8-3
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,22 @@ public type JsonPathRawTemplate object {
2626
};
2727

2828
# Extract details from the given JSON value using the provided query template expression
29+
#
30+
# ```ballerina
31+
# read({id: 1, "name": "John Doe"}, `$.name`) => "John Doe"
32+
# ```
33+
#
2934
# + 'json - JSON value
3035
# + query - JSON path expression
3136
# + return - extracted details as JSON value, a jsonpath:Error otherwise
3237
public isolated function read(json 'json, JsonPathRawTemplate query) returns json|Error {
3338
return readJson('json, new JsonPathRawTemplateImpl(query));
3439
}
3540

36-
public class JsonPathRawTemplateImpl {
41+
class JsonPathRawTemplateImpl {
3742
*JsonPathRawTemplate;
3843

39-
public isolated function init(JsonPathRawTemplate jsonPathRawTemplate) {
44+
isolated function init(JsonPathRawTemplate jsonPathRawTemplate) {
4045
self.strings = jsonPathRawTemplate.strings;
4146
self.insertions = jsonPathRawTemplate.insertions;
4247
}
@@ -46,6 +51,6 @@ public class JsonPathRawTemplateImpl {
4651
# + 'json - JSON value
4752
# + query - JSON path expression
4853
# + return - extracted details as JSON value, a jsonpath:Error otherwise
49-
public isolated function readJson(json 'json, JsonPathRawTemplateImpl query) returns json|Error = @java:Method {
54+
isolated function readJson(json 'json, JsonPathRawTemplateImpl query) returns json|Error = @java:Method {
5055
'class: "io.ballerina.lib.data.jsonpath.BJsonPath"
5156
} external;

ballerina/tests/jsonpath_simple_tests.bal

+6
Original file line numberDiff line numberDiff line change
@@ -484,3 +484,9 @@ function testQuery9() returns error? {
484484
19.95
485485
]);
486486
}
487+
488+
@test:Config {}
489+
function testQuery10() returns error? {
490+
json result = check read({id: 1, "name": "John Doe"}, `$.name`);
491+
test:assertEquals(result, "John Doe");
492+
}

build-config/resources/Ballerina.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,19 @@ artifactId = "jsondata-native"
1818
version = "@toml.version@"
1919
path = "../native/build/libs/data.jsondata-native-@project.version@.jar"
2020

21-
[[platform.java11.dependency]]
21+
[[platform.java17.dependency]]
2222
path = "./lib/json-path-@jsonpath.version@.jar"
2323
groupId = "com.jayway.jsonpath"
2424
artifactId = "json-path"
2525
version = "@jsonpath.version@"
2626

27-
[[platform.java11.dependency]]
27+
[[platform.java17.dependency]]
2828
path = "./lib/json-smart-@jsonsmart.version@.jar"
2929
groupId = "net.minidev.json"
3030
artifactId = "json-smart"
3131
version = "@jsonsmart.version@"
3232

33-
[[platform.java11.dependency]]
33+
[[platform.java17.dependency]]
3434
path = "./lib/accessors-smart-@accessors.version@.jar"
3535
groupId = "net.minidev.json"
3636
artifactId = "accessors-smart"

gradle.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ githubJohnrengelmanShadowVersion=8.1.1
1212
underCouchDownloadVersion=4.0.4
1313
researchgateReleaseVersion=2.8.0
1414
ballerinaGradlePluginVersion=2.0.1
15-
javaJsonPathVersion=2.7.0
15+
javaJsonPathVersion=2.9.0
1616
javaJsonSmartVersion=2.4.7
1717
javaAccessorsSmartVersion=2.4.7
1818
stdlibIoVersion=1.6.0

0 commit comments

Comments
 (0)