{
  "schemaVersion": 1,
  "kind": "kittycord-studio",
  "language": "javascript",
  "metadata": {
    "id": "local.json-workbench",
    "name": "JSON Workbench",
    "version": "1.0.0",
    "author": "Kittencord contributors"
  },
  "source": "globalThis.kittycordPlugin = /** @type {KittyPlugin} */ ({\n    start(api) {\n        let result = \"Save JSON in settings, then format, minify or inspect a JSON Pointer.\";\n        const show = () => api.publishPanel({title:\"JSON Workbench\",text:result,actions:[{id:\"format\",label:\"Format JSON\"},{id:\"minify\",label:\"Minify JSON\"},{id:\"pointer\",label:\"Read pointer\"}],settings:[{id:\"json\",label:\"JSON input\",type:\"text\",default:'{\"hello\":\"Kittencord\"}'},{id:\"pointer\",label:\"JSON Pointer (e.g. /items/0)\",type:\"text\",default:\"\"}]});\n        api.onAction(id => {\n            try {\n                let value = JSON.parse(String(api.settings.json ?? \"\"));\n                if (id === \"pointer\") {\n                    const pointer = String(api.settings.pointer ?? \"\");\n                    if (pointer && !pointer.startsWith('/')) throw new Error(\"A JSON Pointer must be empty or begin with /.\");\n                    for (const encoded of pointer ? pointer.slice(1).split('/') : []) {\n                        if (/~(?:[^01]|$)/.test(encoded)) throw new Error(\"Invalid pointer escape. Use ~0 for ~ and ~1 for /.\");\n                        const key = encoded.replace(/~1/g, '/').replace(/~0/g, '~');\n                        if (value === null || typeof value !== \"object\" || !Object.prototype.hasOwnProperty.call(value, key) || Array.isArray(value) && !/^(0|[1-9][0-9]*)$/.test(key)) throw new Error(\"Pointer does not exist in this document.\");\n                        value = value[key];\n                    }\n                }\n                result = JSON.stringify(value, null, id === \"minify\" ? 0 : 2);\n                if (result.length > 2000) throw new Error(\"Formatted result exceeds 2000 characters. Use Minify JSON or select a smaller value with a pointer.\");\n            } catch (error) { result = error instanceof Error ? error.message : \"Invalid JSON.\"; }\n            show();\n        }); show();\n    }\n});",
  "tokens": [],
  "tests": [],
  "api": "utility-v1"
}