Scripts

Scripts

You can write your own scripts to further process JSON string.

The Scripts feature is build upon Apple’s JavaScriptCore Framework (opens in a new tab). It provides the ability to evaluate JavaScript programs from within OK JSON.

JavaScriptCore is a JavaScript engine. Thus the Web APIs (opens in a new tab) like window, document and XMLHttpRequest are not available.

However, OK JSON offers some simple yet powerful APIs to let you interact with the app. You can do a lot things with them.

An example script:

/*
@okjson.schemaVersion 1
@okjson.name Copy As Minified JSON
@okjson.description Copy input string as minified JSON.
@okjson.icon square.on.circle
@okjson.keyboardShortcut ⌥⌘m
@okjson.preprocessInput yes
@okjson.openResultInNewWindow no
@okjson.author OK JSON
@okjson.authorURL https://okjson.app
*/
 
function main(object) {
  let result = JSON.stringify(object);
  $utility.copyString(result)
  $alert.info("Copied As Minified JSON", "Length: " + result.length)
  return result
}

You can have a “Copy As Minified JSON” action with a couple lines of code.

If you need more APIs to help with your scripts, please let us know.