Copy As Minified JSON

Copy As Minified JSON

Build a script to copy as minified JSON.

Getting Started

Create a script file in the script folder with the following code.

This example also includes a keyboard shortcut ⌥ ⌘ m.

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

Example JSON String for Testing

{
  "name": "OK JSON",
  "version": "2.0.0",
  "platform": "macOS"
}