
Company News
/Security News
Socket Selected for OpenAI's Cybersecurity Grant Program
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.
@jsonui/react
Advanced tools
This is a Json markup language to define User Interface as a canvas where you can draw with Json definition.
When you change the Json definition, the interface immediately reflects on what you defined/changed.
Actually JSONUI is available for react and react-native. It will be able to integrate to 99% of the cross-platform environments, thanks for reactjs ecosystem
The UI definition contains a layout definition and components configuration as well. The most important it has a built in state management system.
Build a data driven UI. The "definition" is changeable by developer anytime and any reason. If you would like to build a remote controlled app or a form generator app, I hope you will love it.
npm install @jsonui/react
yarn add @jsonui/react
The JsonUI Component is a canvas and the model parameter contains the UI definition in Json format.
import { JsonUI } from '@jsonui/react'
const Canvas = () => <JsonUI model={{ $comp: 'Text', $children: 'Hello World', style: { fontSize: 30 } }} />
The Json Markup language has 3 important part
The "$comp" key represents the name of a predefined react component. The predefined components:
div html tagbutton html tagReact.Fragment componentimage html tagp html tagThe props of the components are the same as in the normal react world.
The "$children" key represents the children of the component.
It can be array, object or primitive like text, number, boolean
{ "$comp": "Text", "$children": "Hello World" }
{ "$comp": "Text", "$children": 124 }
{ "$comp": "Text", "$children": [1,2,3] }
{ "$comp": "Text", "$children": null }
{ "$comp": "View", "$children": [
{ "$comp": "Text", "$children": "Hello World" }
]
}
When the component has an interaction with user or a triggered event, the "$action" key will represent it, for example onClick, onChange or onPress
{ "$comp": "Button", "$children": "Login", "onPress": { "$action": "navigate", "route": "LoginPage" } }
The action is really a predefined function when it will fire, when the event has triggered.
The "$action" can add a dynamic value for properties or components. It's a function which will be called at render time of the component. Depends on environment data. For example JSONUI contains a basic internalisation solution.
{ "$comp": "Text", "$children": "Hello World" }
{ "$comp": "Text", "$children": { "$modifier": "t", "key": "Helló Világ" } }
Easily.
const Canvas = () => <JsonUI model={jsonData}
"components" = {
{
navigate: ({route}) => navigate(route)
}
}
"functions" = {
{
t: ({key}) => t(key)
}
}/>
The state management is another layer of the JSNOUI. It's represent a permissive and dynamic tree graf structure. Like a JSON file.
Each app has a separated data space, based on the id param of JsonUI component.
Each app has multiple store represent multiple data tree or separate storage.
Actually the data store is persistent. (it will be configurable soon if there is interest in it)
You can define unlimited data store. What you need is, just use a specific name in JSON Definition, and it will automatically create at the first use.
JSONUI use json-pointer to tell the path what kind of data we need.
We have 2 built-in function which can help to read and write your state management.
Let's see some example
{ "users": [{ "username": "John Doe" }] }
{ "$comp": "Text", "$children": { "$modifier": "get", "store": "data", "path": "/users/0/username" } }
{ "$comp": "Button", "$children": "Change username", "onPress": { "$modifier": "set", "store": "data", "path": "/users/0/username", "value": "John Doe 2" } }
{ "users": [{ "username": "John Doe2" }] }
{
"$comp": "Input",
"value": { "$modifier": "get", "store": "questionnaire1", "path": "/firstName" },
"onChange": { "$action": "set", "store": "questionnaire1", "path": "/firstName" }
}
You can manipulate the data when read or write it with jsonata.
{ "$comp": "Text", "children": { "$modifier": "get", "store": "data", "path": "/prevNumber", "jsonataDef": "'Next Number: ' & (1+$)" } }
You can use absolute, relative path and ./ ../ still works. few examples
{ "path": "/prevNumber" }
{ "path": "prevNumber" }
{ "path": "../prevNumber" }
{ "path": "../../prevNumber" }
Somethimes we need to handle dynamic data for example a list.
{ "subscribed": { "list": [{ "name": "John Doe" }] } }
{
"$comp": "Fragment",
"isList": true,
"$pathModifiers": {
"data": { "path": "/subscribed/list" }
},
"listItem": {
"$comp": "Input",
"value": { "$modifier": "get", "store": "data", "path": "name" },
"onChange": { "$action": "set", "store": "data", "path": "name" }
}
}
This little technique can change the relative path nestedly as well.
Copyright (c) 2022 Istvan Fodor.
FAQs
Json markup language to define User Interface
The npm package @jsonui/react receives a total of 8 weekly downloads. As such, @jsonui/react popularity was classified as not popular.
We found that @jsonui/react demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.

Security News
Socket CEO Feross Aboukhadijeh joins 10 Minutes or Less, a podcast by Ali Rohde, to discuss the recent surge in open source supply chain attacks.

Research
/Security News
Campaign of 108 extensions harvests identities, steals sessions, and adds backdoors to browsers, all tied to the same C2 infrastructure.