Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/williamtroup/jhson.js
📃 A JavaScript library for converting between HTML and JSON, with binding, templating, attributes, and CSS support.
https://github.com/williamtroup/jhson.js
angular attributes binding clientside-rendering conversation convert css css-properties formatting html json react rendering serverside-rendering template-engine templating text typescript
Last synced: 15 days ago
JSON representation
📃 A JavaScript library for converting between HTML and JSON, with binding, templating, attributes, and CSS support.
- Host: GitHub
- URL: https://github.com/williamtroup/jhson.js
- Owner: williamtroup
- License: mit
- Created: 2024-02-28T19:40:44.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2024-09-09T21:23:39.000Z (2 months ago)
- Last Synced: 2024-09-10T02:09:02.863Z (2 months ago)
- Topics: angular, attributes, binding, clientside-rendering, conversation, convert, css, css-properties, formatting, html, json, react, rendering, serverside-rendering, template-engine, templating, text, typescript
- Language: TypeScript
- Homepage: https://www.william-troup.com/jhson-js/
- Size: 639 KB
- Stars: 19
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE.txt
- Code of conduct: CODE_OF_CONDUCT.md
- Security: SECURITY.md
Awesome Lists containing this project
README
JHson.js[![Tweet](https://img.shields.io/twitter/url/http/shields.io.svg?style=social)](https://twitter.com/intent/tweet?text=JHson.js%2C%20a%20free%20JavaScript%json%20converter&url=https://github.com/williamtroup/JHson.js&hashtags=javascript,json,html,converter)
[![npm](https://img.shields.io/badge/npmjs-v2.3.0-blue)](https://www.npmjs.com/package/jhson.js)
[![nuget](https://img.shields.io/badge/nuget-v2.3.0-purple)](https://www.nuget.org/packages/JHson.js/)
[![license](https://img.shields.io/badge/license-MIT-green)](https://github.com/williamtroup/JHson.js/blob/main/LICENSE.txt)
[![discussions Welcome](https://img.shields.io/badge/discussions-Welcome-red)](https://github.com/williamtroup/JHson.js/discussions)
[![coded by William Troup](https://img.shields.io/badge/coded_by-William_Troup-yellow)](https://william-troup.com/)>
📃 A JavaScript library for converting between HTML and JSON, with binding, templating, attributes, and CSS support.
>v2.3.0
What features does JHson.js have?
- 😏 Zero-dependencies and extremely lightweight!
- 🦾 Written in TypeScript, allowing greater support for React, Angular, and other libraries!
- 💻 Full API available via public functions.
- 🌈 Full support for Attributes, CSS style properties, and formatted text!
- ⭐ Write your JSON directly to any DOM element for rendering, or get the base element for use elsewhere.
- 📋 Copy the layout for an entire page without additional files!
- 🔍 Apply additional filters to exclude specific node types, CSS styles, attributes, etc.
- 🔠 Data templating for text (with defaults support).
- 🎥 Write CSS directly back to the head for each element!
- 💧 Bind JSON directly to DOM elements!
- 📷 Include and write images as Base 64 URLs.
What browsers are supported?
All modern browsers (such as Google Chrome, FireFox, and Opera) are fully supported.
What are the most recent changes?
To see a list of all the most recent changes, click [here](https://www.william-troup.com/jhson-js/documentation/recent-changes.html).
How do I install JHson.js?
You can install the library with npm into your local modules directory using the following command:
```markdown
npm install jhson.js
```Or, you can download the latest zipped up version [here](https://www.william-troup.com/jhson-js/download.html).
Or, you can also use the following CDN links:
```markdown
https://cdn.jsdelivr.net/gh/williamtroup/[email protected]/dist/jhson.min.js
https://cdn.jsdelivr.net/gh/williamtroup/[email protected]/dist/jhson.export.js
```
How do I get started?
To get started using JHson.js, do the following steps:
### 1. Prerequisites:
Make sure you include the "DOCTYPE html" tag at the top of your HTML, as follows:
```markdown
```
### 2. Include Files:
```markdown
```
### 3. Getting/Rendering JSON:
```markdown
JHson.js
This is a {{template_type | basic}} example of how to use JHson.js ... with template data {{template_data}}.
var header = document.getElementById( "header" );
var json = $jhson
.json()
.includeAttributes( true )
.includeDataAttributes( true )
.includeCssProperties( true )
.includeText( true )
.includeChildren( true )
.includeImagesAsBase64( false )
.friendlyFormat( true )
.indentSpaces( 2 )
.ignoreNodeTypes( "q" )
.ignoreNodeCondition( null )
.ignoreCssProperties( "padding" )
.ignoreAttributes( "data-your-attribute" )
.generateUniqueMissingIds( false )
.generateUniqueMissingNames( false )
.propertyReplacer( null )
.get( header );$jhson
.html()
.json( json )
.templateData( { "{{template_data}}": "this template data" } )
.removeOriginalAttributes( true )
.removeOriginalDataAttributes( true )
.clearOriginalHTML( true )
.addCssToHead( false )
.clearCssFromHead( false )
.logTemplateDataWarnings( false )
.addAttributes( true )
.addDataAttributes( true )
.addCssProperties( true )
.addText( true )
.addChildren( true )
.insertBefore( false )
.write( header );var element = $jhson
.html()
.json( json )
.templateData( { "{{template_data}}": "this template data" } )
.removeOriginalAttributes( true )
.removeOriginalDataAttributes( true )
.clearOriginalHTML( true )
.addCssToHead( false )
.clearCssFromHead( false )
.logTemplateDataWarnings( false )
.addAttributes( true )
.addDataAttributes( true )
.addCssProperties( true )
.addText( true )
.addChildren( true )
.get();```
### 4. DOM Element Binding (for writing JSON as HTML):
```markdown
Your HTML.
```To see a list of all the available binding options you can use for "data-jhson-js", click [here](https://www.william-troup.com/jhson-js/documentation/binding-options.html).
To see a list of all the available custom triggers you can use for "data-jhson-js", click [here](https://www.william-troup.com/jhson-js/documentation/binding-options-custom-triggers.html).
### 5. Finishing Up:
That's it! Nice and simple. Please refer to the code if you need more help (fully documented).
How do I go about customizing JHson.js?
To customize, and get more out of JHson.js, please read through the following documentation.
### 1. Public Functions:
To see a list of all the public functions available, click [here](https://www.william-troup.com/jhson-js/documentation/public-functions.html).
### 2. Configuration:
Configuration options allow you to customize how JHson.js will function. You can set them as follows:
```markdown
$jhson.setConfiguration( {
safeMode: false
} );```
To see a list of all the available configuration options you can use, click [here](https://www.william-troup.com/jhson-js/documentation/options.html).