OK JSON
OK JSON 是一款 JSON 查看工具。Protocol Launcher 允许您生成 OK JSON URL scheme 链接。
使用方式
有两种使用此库的方式:
- 按需导入(On-Demand):从子路径导入支持 tree-shaking,保持较小的打包体积。
- 完整导入(Full Import):从根包导入更方便,但会包含所有应用模块。
生产构建建议选择按需导入;快速脚本或演示可以使用完整导入。
选择安装方式
按需加载
推荐使用。生产环境优化。
全量导入
使用便捷。适合快速脚本。
注意事项
OK JSON 官方 URL Schemes 页面只记录了五个动作:okjson://paste、okjson://new?content=...、okjson://history、okjson://scripts-panel 和 okjson://script/...。此模块只暴露这些官方记录的动作。
newJson() 接收原始 JSON 字符串,并将其序列化为官方的 URL 编码 content 查询参数。runScript() 接收不带 .js 扩展名的自定义脚本文件名,与官方脚本 URL 格式保持一致。
从剪贴板查看 JSON 字符串
ts
import { paste } from 'protocol-launcher/ok-json'
const url = paste()查看 JSON 字符串
ts
import { newJson } from 'protocol-launcher/ok-json'
const url = newJson({
content: '{"hello":"world"}',
})显示历史窗口
ts
import { history } from 'protocol-launcher/ok-json'
const url = history()显示脚本面板窗口
ts
import { scriptsPanel } from 'protocol-launcher/ok-json'
const url = scriptsPanel()运行脚本
ts
import { runScript } from 'protocol-launcher/ok-json'
const url = runScript({
scriptFileNameWithoutJsExtension: 'copy-minified-json',
})生成的 URL
ts
paste()
// => 'okjson://paste'
newJson({
content: '{"hello":"world"}',
})
// => 'okjson://new?content=%7B%22hello%22%3A%22world%22%7D'
history()
// => 'okjson://history'
scriptsPanel()
// => 'okjson://scripts-panel'
runScript({
scriptFileNameWithoutJsExtension: 'copy-minified-json',
})
// => 'okjson://script/copy-minified-json'