Skip to content

Instantly share code, notes, and snippets.

@gambitier
Last active August 26, 2022 12:43
Show Gist options
  • Select an option

  • Save gambitier/e850b2af402d8ed730a5561701daf940 to your computer and use it in GitHub Desktop.

Select an option

Save gambitier/e850b2af402d8ed730a5561701daf940 to your computer and use it in GitHub Desktop.
<script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/table-to-json@1.0.0/lib/jquery.tabletojson.min.js" integrity="sha256-H8xrCe0tZFi/C2CgxkmiGksqVaxhW0PFcUKZJZo1yNU=" crossorigin="anonymous"></script>
<script type="text/javascript">
// Basic Usage
var table = $('#mydata').tableToJSON();
// table == [{"First Name"=>"Jill", "Last Name"=>"Smith", "Score"=>"disqualified"},
// {"First Name"=>"Eve", "Last Name"=>"Jackson", "Score"=>"94"},
// {"First Name"=>"John", "Last Name"=>"Doe", "Score"=>"80"},
// {"First Name"=>"Adam", "Last Name"=>"Johnson", "Score"=>"67"}]
console.log(JSON.stringify(table))
// Ignore first column (name)
// var table = $('#mydata').tableToJSON({
// ignoreColumns: [0]
// });
// table == [{"Last Name"=>"Smith", "Score"=>"disqualified"},
// {"Last Name"=>"Jackson", "Score"=>"94"},
// {"Last Name"=>"Doe", "Score"=>"80"},
// {"Last Name"=>"Johnson", "Score"=>"67"}]
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment