JHson.js
📃 A JavaScript library for converting between HTML and JSON, with binding, templating, attributes, and CSS support.
Install / Use
/learn @williamtroup/JHson.jsREADME
<p align="center">📃 A JavaScript library for converting between HTML and JSON, with binding, templating, attributes, and CSS support.</p> <p align="center">v2.4.0</p><br /> <br /> <h1>What features does JHson.js have?</h1>
- 😏 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. <br />
All modern browsers (such as Google Chrome, FireFox, and Opera) are fully supported. <br> <br>
<h1>What are the most recent changes?</h1>To see a list of all the most recent changes, click here. <br> <br>
<h1>How do I install JHson.js?</h1>You can install the library with npm into your local modules directory using the following command:
npm install jhson.js
Or, you can download the latest zipped up version here.
Or, you can also use the following CDN links:
https://cdn.jsdelivr.net/gh/williamtroup/JHson.js@2.4.0/dist/jhson.min.js
https://cdn.jsdelivr.net/gh/williamtroup/JHson.js@2.4.0/dist/jhson.export.js
<br>
<br>
<h1>How do I get started?</h1>
To get started using JHson.js, do the following steps: <br> <br>
1. Prerequisites:
Make sure you include the "DOCTYPE html" tag at the top of your HTML, as follows:
<!DOCTYPE html>
<br>
2. Include Files:
<script src="dist/jhson.js"></script>
<br>
3. Getting/Rendering JSON:
<div id="header" class="header">
<h1>JHson.js</h1>
<p>This is a {{template_type | basic}} example of how to use <b>JHson.js</b> ... with template data {{template_data}}.</p>
</div>
<script>
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();
</script>
<br>
4. DOM Element Binding (for writing JSON as HTML):
<div data-jhson-js="{ 'json': 'json string' }">
Your HTML.
</div>
To see a list of all the available binding options you can use for "data-jhson-js", click here.
To see a list of all the available custom triggers you can use for "data-jhson-js", click here.
<br>5. Finishing Up:
That's it! Nice and simple. Please refer to the code if you need more help (fully documented). <br> <br>
<h1>How do I go about customizing JHson.js?</h1>To customize, and get more out of JHson.js, please read through the following documentation. <br> <br>
1. Public Functions:
To see a list of all the public functions available, click here. <br> <br>
2. Configuration:
Configuration options allow you to customize how JHson.js will function. You can set them as follows:
<script>
$jhson.setConfiguration( {
safeMode: false
} );
</script>
To see a list of all the available configuration options you can use, click here.
Related Skills
bluebubbles
345.9kUse when you need to send or manage iMessages via BlueBubbles (recommended iMessage integration). Calls go through the generic message tool with channel="bluebubbles".
slack
345.9kUse when you need to control Slack from OpenClaw via the slack tool, including reacting to messages or pinning/unpinning items in Slack channels or DMs.
frontend-design
106.4kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
Writing Hookify Rules
106.4kThis skill should be used when the user asks to "create a hookify rule", "write a hook rule", "configure hookify", "add a hookify rule", or needs guidance on hookify rule syntax and patterns.
