Skip to content

Instantly share code, notes, and snippets.

@Aeon
Last active November 16, 2016 00:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Aeon/75a56adc8beac4dc1838e013fc9eeade to your computer and use it in GitHub Desktop.
Save Aeon/75a56adc8beac4dc1838e013fc9eeade to your computer and use it in GitHub Desktop.
  1. strip beginning/ending single or double quotes
^([^:]*): (?:["'])?(.*?)(?:["'])?$

$1: $2
  1. replace quotes around KEYS with placeholders, if the key has quotes, preserve indents
^(\s*)(?:["'])([^:]*?)(?:["'])?: (.*)$

$1###$2###: $3
  1. replace all remaining unescaped double quotes with escaped double quotes
([^\\])"

$1\"

  1. replace placeholders around quote keys with quotes
^(\s*)###([^:]*?)###?: (.*)$

$1"$2": $3

  1. add double quotes around all values
^([^:]*): (.*)$

$1: "$2"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment