• Stars
    star
    166
  • Rank 222,892 (Top 5 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created over 6 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

JSONX - Create React Elements, JSX and HTML from JSON

JSONX

Coverage Status Build, Test & Coverage

Description

JSONX is a module that creates React Elements, JSX and HTML from JSON.

Declarative

The JSONX web module comes with batteries included so you can use JSONX in the browser without transpilers or any additional setup/configuration. The JSONX UMD is ideal for JAMstack Applications.

Embeddable

JSONX can also be used in existing react applications if you want to dynamically create elements with JSON. This works great for many scenarios when you want to manage your application views and components in a view management system or if you want to dynamically create React elements without using JSX.

Fully Featured

JSONX supports all of Reacts features including Functional (with Hooks), Class-based, Suspense and Lazy components. JSONX supports JSON objects that implement the JXM (JSONX Markup) Spec.

Installation

$ npm i jsonx

Full Documentation


JSONX Manual


Basic Usage

import { * as jsonx } from 'jsonx';
const example_JXM_JSON = {
  component:'p',
  props:{ style:{ color:'blue' } },
  children:'hello world'
};

//Rendering React Components
jsonx.getReactElement(example_JXM_JSON); // => JSX Equivalent: <p style={{color:'blue'}}>hello world</p>

//Generating HTML strings
jsonx.outputHTML({ jsonx: example_JXM_JSON, }); // => '<p style="color:blue;">hello world</p>'

//Generating JSX strings
jsonx.outputJSX({ jsonx: example_JXM_JSON, }); // => '<p style={{color:blue,}}>hello world</p>'

//Rendering HTML Dom with React
jsonx.jsonxRender({ jsonx: example_JXM_JSON, querySelector:'#myApp', });
// <!DOCTYPE html>
//  <body>
//    <div id="myApp">
//      <p style="color:blue;">hello world</p>
//    </div>
// </body>

//you can also use the simplified syntax
const simpleJXM_JSON = {
  p:{
    props:{ style:{ color:'blue' } },
    children:'hello world'
  }
}

//or if you have an element with no props, simply use {type:children}
const superSimpleJXM = {
  ul:[
    {li:'first!'},
    {li:'second!'},
  ]
}

JXM JSON Spec

JSONX works by using JXM JSON to create react elements. JXM JSON Objects are valid JSON Objects that more or less mimics JSX in JSON notation with a couple of special properties. The properties for JSONX JSON are the arguments passed to React.createElement. The only required property is the component (which is passed as the type argument)

React.createElement(
  type,
  [props],
  [...children]
)

You can pass React component libraries for additional components, or you own custom components (see External and Custom Components and Using Advanced Props for more details).

Development

Note Make sure you have typescript installed

$ npm i -g typescript 

For generating documentation

$ npm run doc

Notes

Check out https://repetere.github.io/jsonx/ for the full jsonx Documentation

Testing

$ npm test

Contributing

Fork, write tests and create a pull request!

License


MIT

More Repositories

1

periodicjs

Periodic is a library for rapidly developing database agnostic enterprise applications and APIs with express & node.js
JavaScript
40
star
2

modelscript

REPO MOVED TO https://github.com/repetere/jsonstack-data - Data Science and Machine learning in JavaScript
JavaScript
39
star
3

tensorscript

REPO MOVED TO https://repetere.github.io/jsonstack-model - Deep Learning Classification, Clustering, LSTM Time Series and Regression with Tensorflow
JavaScript
37
star
4

component.selectfx

Some inspiration for styling a custom version of the select element. There are many possibilities and today we are exploring some ideas of how to let the user select a choice in style. Inspired by http://tympanus.net/codrops/2014/07/10/inspiration-for-custom-select-elements/
JavaScript
14
star
5

lowkie

Lowkie is an ORM for LokiJS. LokiJS is a document oriented database written in javascript. LokiJS is used to store javascript objects as documents and follows familiar nosql paradigms to query and retrieve documents. Lowkie by default saves data to disk but for client-side usage, data persists in-memory or client side storage (e.g., a session store / localstorage)
JavaScript
10
star
6

promisie

promisify and promisifyAll methods for ES6 native Promises
TypeScript
6
star
7

stylie.treeview

Pure CSS collapsible tree menu
JavaScript
5
star
8

jsonstack-model

Deep Learning Classification, LSTM Time Series, Regression and Multi-Layered Perceptrons with Tensorflow
TypeScript
5
star
9

periodicjs.ext.reactadmin

asyncadmin update
JavaScript
4
star
10

jsonm-data

REPO MOVED: https://github.com/repetere/jsonstack-data - Data Science and Machine learning in TypeScript
TypeScript
4
star
11

component.fullscreen-form

An experimental fullscreen form concept where the idea is to allow distraction-free form filling with some fancy animations when moving between form fields. Inspired by http://tympanus.net/codrops/2014/07/30/fullscreen-form-interface/
JavaScript
4
star
12

jsona

React based Progressive Web Apps with JSON
TypeScript
2
star
13

tensorx

tensorscript with node tensorflow bindings
JavaScript
2
star
14

stylie.notifications

Simple ideas & effects for website notifications, ported from: http://tympanus.net/Development/NotificationStyles/growl-genie.html
CSS
1
star
15

manuscript

Universal React web and React native application generator.
JavaScript
1
star
16

silkscreen

minimal modal windows with no dependencies
CSS
1
star
17

component.collection-linotype

full page composition module
JavaScript
1
star
18

stylie.slideshows

A very simple 100% width slider that scales down to mobile
JavaScript
1
star
19

platterjs

minimizable ui window manager
JavaScript
1
star
20

periodicjs.core.data

periodicjs.core.controller db adapters
JavaScript
1
star
21

jsonstack-math

math, linear algebra, matrix and other helpers
TypeScript
1
star
22

ribbon

simple notification UI element
JavaScript
1
star
23

jsonm

Construct AI & ML models with JSON using Tensorflow & TypeScript
TypeScript
1
star