Extension::JsonPathExtract Method
Syntax
.PathExtract as c (json as C, path as C [, base as N])
Arguments
- json
Json String.
- path
Path to extract json from
- base
Optional Array Base Offset (defaults to 1 for Xbasic array symantics)
Description
Return the json from the path. The 'base' argument indicates array/position start - Xbasic should be 1, javascript should be 0.
Discussion
Unlink the json_extract() function, which drills down and finds every occurrence of a tag, PathExtract requires a fully qualified path to element.
Example
dim json as c = <<%json% { "fname": "john", "lname": "public", "address": { "address1": "12 main street", "address2": "apt 2b", "state": "NY", "city": "Springfield" }, "bill_address": { "address1": "12 main street", "address2": "apt 2b", "state": "NY", "city": "Statesville" } } %json% ? json_extract(json,"city") = ["Springfield","Statesville"] ? extension::json::PathExtract(json,"city") = "" ? extension::json::PathExtract(json,"address.city") = "Springfield" ? extension::json::PathExtract(json,"bill_address.city") = "Statesville"