format selected text as sorted json

// Name: format-json
// Shortcut: cmd shift j
// Author: David Adams
// Twitter: @dadamssg
import "@johnlindquist/kit"
let jsonabc = await npm("jsonabc")
let text = await getSelectedText()
let json
try {
json = jsonabc.sort(String(text).trim(), false, 2)
} catch (e) {
notify(e.message)
exit()
}
await setSelectedText(json)

Install format-json

Turns this:

[{"z": false, "_id":"631b4ed565976c544dbce557","index":0,"guid":"89965508-5576-46fb-9849-e6ec07918d73","isActive":false,"balance":"$2,996.82","friends":[{"name":"Lara Humphrey","id":0}],"greeting":"Hello, undefined! You have 9 unread messages.","favoriteFruit":"strawberry"}]

into this(notice the sorted keys):

[
{
"_id": "631b4ed565976c544dbce557",
"balance": "$2,996.82",
"favoriteFruit": "strawberry",
"friends": [
{
"id": 0,
"name": "Lara Humphrey"
}
],
"greeting": "Hello, undefined! You have 9 unread messages.",
"guid": "89965508-5576-46fb-9849-e6ec07918d73",
"index": 0,
"isActive": false,
"z": false
}
]