Table of Contents

JSONPath

C10 - initial

jsonpath (Sifts)
TypeCorrade progressive sift
Siftjsonpath
Parametersa string representing a JSON path
DescriptionThe jsonpath sift will extract JSON elements matching the provided JSON path.
Last ChangesNone

The jsonpath sift will extract JSON elements matching the provided JSON path.

Arguments

Position Type Description Example
0 a string representing a JSON path return all JSON elements that the path resolves to $.query.pages.*.extract

Example

In case the returned data is expected to return JSON, then the JSONPath sift can be used to extract a subtree or a single value. For example, suppose we would like to retrieve the value of the extract key in the Wikipedia query https://en.wikipedia.org/w/api.php?format=json&action=query&prop=extracts&exintro&explaintext&redirects=1&titles=Homie.

Were we to issue the HTTP command in order to retrieve a summary of the article named Homie:

        llInstantMessage(CORRADE, 
            wasKeyValueEncode(
                [
                    "command", "HTTP",
                    "group", wasURLEscape(GROUP),
                    "password", wasURLEscape(PASSWORD),
                    "action", "get",
                    "type", "text",
                    "URL", wasURLEscape("https://en.wikipedia.org/w/api.php?format=json&action=query&prop=extracts&exintro&explaintext&redirects=1&titles=Homie"),
                    "sift", wasListToCSV([
                            "JSONPath",
                            wasURLEscape("$.query.pages.*.extract")
                    ]),
                    "callback", wasURLEscape(URL)
                ]
            )
        );

then the sift JSONPath with the value $.query.pages.*.extract would return the page extract in the data key.

Notes

  • As one might have guessed, a JSON path is the equivalent of XPath for XML but for JSON. Unfortunately, JSONPath has not been formalized and officially a JSON path is not part of the JSON standard. Nevertheless, since JSON is a well-structured formatting language that, just like XML, can be expressed as a tree structure, the concept of a JSON path remains entirely valid. As will all things that have not yet been formally standardized, be weary of using this feature, and, if there is an easy alternative, then it should be preferred.

secondlife/scripted_agents/corrade/api/sifts/jsonpath.txt ยท Last modified: 2022/11/24 07:46 by 127.0.0.1

Access website using Tor Access website using i2p Wizardry and Steamworks PGP Key


For the contact, copyright, license, warranty and privacy terms for the usage of this website please see the contact, license, privacy, copyright.