Giter Site home page Giter Site logo

ashok19r91d / serialize2json Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 0.0 15 KB

Serialize standatd HTML table to JSON string using data-* attributes.

License: GNU General Public License v3.0

JavaScript 100.00%
html-table-to-json json-table serialization

serialize2json's Introduction

Serialize2JSON

Serialize standatd HTML table to JSON string using data-* attributes.

How to Implement and Configure:-

For any table requires JSON serialization add class json-table

  • .json-table must contain following attribute data-target="jQuerySelector"
  • .json-table must defined <tbody> tag.
  • .json-table rows (tr tags) should define json attributes and respective value using html5 data-* attributes.
  • .json-table may include data-ignore attribute to specify which are all data attribute which required to exclude from serialization.
  • Inside java script call SerializeHtmlToJson();

Sample Code HTML:-

<table class="json-table" data-target="#jsonData" data-ignore="sortable,attr3">
    <tbody>
        <tr data-attr1="1.1" data-attr2="2.1" data-attr3="3.1">
            <td>Column1.1</td>
            <td>Column2.1</td>
        </tr>
        <tr data-attr1="1.2" data-attr2="2.2" data-attr3="3.2" data-attr4="4.2" data-sortable="true">
            <td>Column1.2</td>
            <td>Column2.2</td>
        </tr>
    </tbody>
</table>

Output:-

[
    { "attr1" : "1.1", "attr2" : "2.1"},
    { "attr1" : "1.2", "attr2" : "2.2", "attr4" : "4.2"}
]

Limitations:-

If you need to extend this plugin for table plugins (other than DataTable) you may need to destroy plugins before calling function.

Where Results stored:-

Serialized JSON Output to set as value to jQuery control specified in data-target = ""; for example's case it's saved in object $('#jsonData'); can be retrieved with following code $('#jsonData').val()

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.