Skip to content

Instantly share code, notes, and snippets.

@aral
Created November 13, 2011 16:14
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save aral/1362273 to your computer and use it in GitHub Desktop.
Save aral/1362273 to your computer and use it in GitHub Desktop.
CoffeeScript to JSON script for OS X
coffee --print --compile $1.coffee | sed '1s/^.//' | sed 's/ });/}/' | sed "s/\([^ '\"].*[^ '\"]\):/\"\1\":/" > $1.json
@wlaurance
Copy link

coffee --print --bare $1.coffee | sed '1s/&.//' | sed 's/});/}/' | sed 's/({/{/' | sed "s/\([^ '\"].*[^ '\"]\): /\"\1\": /1" > $1.json

Try this. Note the spaces after :
I have URLS as values and this was causing it to put quotes around part of it. The space after : fixed this.

@onetom
Copy link

onetom commented Nov 28, 2013

With a bit more simplification and handling the input both from stdin and from a file name parameter:

#!/bin/sh
echo \{
    cat $1 | \
    coffee --print --bare --compile --stdio | \
    sed -e '1,2d; $d' | \
    sed "s/\([^ '\"].*[^ '\"]\): /\"\1\": /"
echo \}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment