Project

jsoner

0.01
No commit activity in last 3 years
No release in over 3 years
Serialize HTML tables into JSON in Ruby
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

~> 1.3
~> 1.6.0
>= 0
~> 2.14.1
 Project Readme

Jsoner

Serialize HTML tables into JSON in Ruby.
Gem Version Build Status

Installation

Add this line to your application's Gemfile:

gem 'jsoner'

And then execute:

$ bundle

Or install it yourself as:

$ gem install jsoner

Usage

html = <<-eohtml
    <table id='example-table'>
      <thead>
        <tr>
          <th>First Name</th>
          <th>Last Name</th>
          <th>Points</th></tr>
      </thead>
      <tbody>
        <tr>
          <td>Jill</td>
          <td>Smith</td>
          <td>50</td></tr>
        <tr>
          <td>Eve</td>
          <td>Jackson</td>
          <td>94</td></tr>
        <tr>
          <td>John</td>
          <td>Doe</td>
          <td>80</td></tr>
        <tr>
          <td>Adam</td>
          <td>Johnson</td>
          <td>67</td></tr>
      </tbody>
    </table>
  eohtml

# Convert HTML table into Json

json = Jsoner.parse(html)

# output json => 
# 
#   [ {"First Name"=>"Jill", "Last Name"=>"Smith",   "Points"=>"50"},
#     {"First Name"=>"Eve",  "Last Name"=>"Jackson", "Points"=>"94"},
#     {"First Name"=>"John", "Last Name"=>"Doe",     "Points"=>"80"},
#     {"First Name"=>"Adam", "Last Name"=>"Johnson", "Points"=>"67"} ]

Or, Jsoner can parse HTML file including HTML table

require 'open-uri'
# you must have table.html file and assign file path correctly.

table = Jsoner.parse(open('table.html'))

# output json => 
# 
#   [ {"First Name"=>"Jill", "Last Name"=>"Smith",   "Points"=>"50"},
#     {"First Name"=>"Eve",  "Last Name"=>"Jackson", "Points"=>"94"},
#     {"First Name"=>"John", "Last Name"=>"Doe",     "Points"=>"80"},
#     {"First Name"=>"Adam", "Last Name"=>"Johnson", "Points"=>"67"} ]

Or you can open Link

require 'open-uri'

table = Jsoner.parse(open('http://www.w3school.com.cn/tiy/t.asp?f=html_table_header'))

# output json => 
#
# [{"姓名"=>"Bill Gates", "电话"=>"555 77 855"}]

THANKS

table-to-json written by @lightswitch05 in JavaScript.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request