+1

add function: jsonpath

Shawn 5 months ago 0

Ketarin's variable parsing and function capabilities leaves little to be desired. You can do almost anything.

However, dealing with FossHub and Logitech, and other sites that now push the relevant data exclusively in a JSON format that we have to manually parse with string manipulation functions is less than optimal. It would be great if there were a function that took a variable as input (the contents would be a JSON structure) with an argument that was a JsonPath expression to pull the information required to populate variables.

This function call would result in the first filename from the input data (mkvtoolnix-64-bit-36.0.0-setup.exe):

   {myJsonVar:jsonpath:$.pool.f[0].n}

Perhaps a prepended value as argument 1 to indicate whether the results should be JSON formatted or have the JSON stripped away and return only the textual results.

sampleoutput
{myJsonVar:jsonpath:0:$.pool.f[0].n}mkvtoolnix-64-bit-36.0.0-setup.exe
{myJsonVar:jsonpath:1:$.pool.f[0].n}[ "mkvtoolnix-64-bit-36.0.0-setup.exe" ]



Using this input JSON:

{
  "ads": {
    "show": true,
    "unit": "imageAdTop"
  },
  "donate": {
    "show": true,
    "unit": "default"
  },
  "pageName": "MKVToolNix",
  "projectId": "5b8f889d59eee027c3d78aab",
  "pool": {
    "p": "5b8f889d59eee027c3d78aab",
    "u": "MKVToolNix.html",
    "c": "CF",
    "f": [
      {
        "n": "mkvtoolnix-64-bit-36.0.0-setup.exe",
        "r": "5d4edb8a4a9c362e9124c6e2",
        "hash": {
          "md5": "11bee3cd204c5187427f819469c954e5",
          "sha1": "04b12c3443638b3276a2898d46f3247bc14f2c5e",
          "sha256": "3716939b85b69d87e07104171e60a34520f53abee1c77d58142ad7e2448c933a"
        },
        "s": false
      },
      {
        "n": "mkvtoolnix-64-bit-36.0.0.7z",
        "r": "5d4edb8a4a9c362e9124c6e2",
        "hash": {
          "md5": "1c3a421cd246234406a3dbe8c7500df9",
          "sha1": "5a33fcf1bf554767e03d6e9aca4ba8a4b76c7809",
          "sha256": "7b5b1a825beb3efb9ed3c995f49e1fbfb86d9f223e06593f7773cc792a49dec3"
        },
        "s": false
      },
      {
        "n": "mkvtoolnix-32-bit-36.0.0-setup.exe",
        "r": "5d4edb8a4a9c362e9124c6e2",
        "hash": {
          "md5": "81b7cc366caf3bbdf8c13cbfd3f2d88f",
          "sha1": "031016704df91bb3154c35c285b2a64b22eb4b0e",
          "sha256": "f3d63bc97af840763f498c0f311ef3ee80861f5c8a5684233779d0878a69b2d7"
        },
        "s": false
      },
      {
        "n": "mkvtoolnix-32-bit-36.0.0.7z",
        "r": "5d4edb8a4a9c362e9124c6e2",
        "hash": {
          "md5": "787e3bbbf50f245c31530a730f073207",
          "sha1": "aa4d929213578de20cf852e2040681003eb03676",
          "sha256": "b09913cb07a385ef40c63f140a72351f2ce3ca6702cf8be20a0bcc06c0dbeb10"
        },
        "s": false
      },
      {
        "n": "MKVToolNix-36.0.0.dmg",
        "r": "5d4edb8a4a9c362e9124c6e2",
        "hash": {
          "md5": "f68a2a7bdbba117f2883d384dffee1ec",
          "sha1": "844fb7cc69d67c965a980134ece8827c4d3676f4",
          "sha256": "f13112bca86713ac68d6a937b2421e50005a63d7e6aa43b151ab3bc0e7c6192e"
        },
        "s": false
      },
      {
        "n": "MKVToolNix_GUI-36.0.0-x86_64.AppImage",
        "r": "5d4edb8a4a9c362e9124c6e2",
        "hash": {
          "md5": "e014e7fbf4f61730bfb07f301cc5031a",
          "sha1": "eadab07dd681a3868afd5b7dfafa8e8c9b949514",
          "sha256": "2a6424fc8b1a01a1d6fa863d9188efa3a4a9f436eb8a56de3a32b7a06d4cf447"
        },
        "s": false
      }
    ]
  },
  "isLatestRelease": true,
  "supportsPushNotification": true,
  "pushNotificationAppId": "518af36c-9d0d-4b05-9103-cfe1c9999de7",
  "domain": "fosshub.com",
  "projectMainUrl": "https://www.fosshub.com/MKVToolNix.html",
  "projectOldUrl": "https://www.fosshub.com/MKVToolNix-old.html"
}

Likewise, a JSONselect function could use the CSS-style query selectors.