block by shawnbot ab11ace1bafa23be290c193049a71cb5

50 US states as JSON

How this was made

  1. Visit the list of U.S. state abbreviations on Wikipedia.

  2. Sort the table by “status of region” to group the states together

  3. Select the cells of all of the states (from “Alabama” to “Wyo.”) and press ⌘C to copy

  4. Cut the TSV in your clipboard to two columns (name and two-letter code)

     pbpaste | cut -d$'\t' -f1,4 | pbcopy
  5. Convert the two-column TSV into line-delimited JSON:

     pbpaste | perl -pne 's/^ *(.+)\t(.+)/{"name":"$1","code":"$2"}/' | pbcopy
  6. Use jq to combine the lines into states-array.json:

     pbpaste | jq -rs > states-array.json
  7. Use jq again to produce states-object.json:

     cat states-array.json | jq 'reduce .[] as $item ({}; . + {($item.code): $})' \
         > states-object.json