Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mislav/gorgeous
Convert between different data formats: JSON, XML, YAML, Ruby, email, URL-encoded
https://github.com/mislav/gorgeous
Last synced: 4 days ago
JSON representation
Convert between different data formats: JSON, XML, YAML, Ruby, email, URL-encoded
- Host: GitHub
- URL: https://github.com/mislav/gorgeous
- Owner: mislav
- License: mit
- Created: 2011-02-10T12:54:41.000Z (about 14 years ago)
- Default Branch: master
- Last Pushed: 2014-03-09T23:51:57.000Z (almost 11 years ago)
- Last Synced: 2025-02-06T11:50:17.523Z (14 days ago)
- Language: Ruby
- Homepage:
- Size: 116 KB
- Stars: 95
- Watchers: 4
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Filthy → gorgeous
Convert between formats.
Usage:
gorgeous [-i] [-F ] [-T ] [-q ] [-o ] FILE ...
This utility converts data between different formats.
Formats are one of: json, xml, yaml, ruby, email, urlInput can be read from STDIN as well as files given on the command-line.
Options:
-i Convert file in-place
-F Input format
-T Output format
-q Query selector in format similar to XPath (see below)
-o Write output to file instead of STDOUTQuery format:
"/items/comments[1]/text" -- 2nd comment body of each item
"/items[-1]/user/full_name" -- name of user for last item
"//user/username" -- usernames of all users anywhere in the document## Prerequisites
It's recommended that you install all of these ruby libraries. They are only loaded when processing specific formats.
* **nokogiri** for HTML/XML
* **yajl-ruby** or **json** for JSON (for Ruby < 1.9)
* **activesupport** (for various stuff)
* **rack** for url
* **mail** for emailAll together now:
$ gem install nokogiri yajl-ruby activesupport rack mail
## Examples
Pipe in standard input:
# auto-detects input as being JSON, displays prettified output:
$ curl -s api.twitter.com/1/statuses/show/40453487309361153.json | gorgeous
# covert from JSON to YAML
$ curl -s | gorgeous -T yaml
# extract Twitter avatar from tweet as text
$ curl -s | gorgeous -T txt -q /user/profile_image_urlPrettify a file in place:
# auto-detects format by extension, prettifies and overwrites the file:
$ gorgeous -i some-data.json
# convert some data to YAML
$ gorgeous -i -F json -T yaml some-dataPrettify some HTML (gorgeous calls it "xml"):
$ curl -s www.1112.net/lastpage.html | gorgeous -F xml
Prettify content in clipboard (on a Mac):
$ pbpaste | gorgeous | pbcopy
# convert from YAML to ruby format and copy to clipboard
$ gorgeous fixture.yml -T ruby | pbcopyParse query strings and URL-encoded POST payloads:
$ echo 'sourceid=chrome&ie=UTF-8&q=filthy+gorgeous' | gorgeous -T yaml
---
sourceid: chrome
q: filthy gorgeous
ie: UTF-8Parse emails:
# extract prettified HTML part of the email:
$ cat email.raw | gorgeous -F email -T xml# extract decoded text part of the email:
$ cat email.raw | gorgeous -F email -T txt# get email headers as JSON:
$ cat email.raw | gorgeous -F email -T json# get only the email subject:
$ cat email.raw | gorgeous -F email -T txt -q /subject