This utility takes JSON and outputs the XML required for the Script Filter in Workflows for the wonderful Mac App Alfred. It can be used in other node.js modules or as a command line utility.
Basic Usage
Command Line
json-to-alfred path/to/data.json
That will output the XML Alfred is looking for. Keep in mind that it is best to use absolute paths in Alfred's Script Filters, a quick which json-to-alfred
can tell you where it is.
Node.js Modules
var jsonToAlfred = ;var data = "results": "title": "Title of Result" "subtitle": "Subtitle" "arg": "Argument passed to next Alfred Workflow item as {query}" "title": "2nd title" "subtitle": "2nd subtitle" "arg": "2nd arg" ; var xml = jsonToAlfred;console;
Creating single records
Alternatively, you could take this approach, which would result in the same as above.
var jsonToAlfred = ;var data = "results": "title": "Title of Result" "subtitle": "Subtitle" "arg": "Argument passed to next Alfred Workflow item as {query}" "title": "2nd title" "subtitle": "2nd subtitle" "arg": "2nd arg" ; console;dataresults;console;
Properties
jsonToAlfred.prefix
Output the prefix of the XML:
jsonToAlfred.suffix
Output the suffix of the XML:
Methods
jsonToAlfred.createItem(result)
Take JSON or a JS Object result
that is this format:
which will output this:
title here subtitle text to copy here display large text here
jsonToAlfred.createItems(results)
The all in one solution; this calls jsonToAlfred.prefix
, then loops through results
passed in - an array of result
objects (see above) and calls jsonToAlfred.createitem()
on each one, then calls jsonToAlfred.suffix
to close it all.