https://github.com/threepointone/jsxn
jsx notation for json trees
https://github.com/threepointone/jsxn
Last synced: about 1 month ago
JSON representation
jsx notation for json trees
- Host: GitHub
- URL: https://github.com/threepointone/jsxn
- Owner: threepointone
- Created: 2016-06-14T12:31:20.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2016-06-14T19:17:09.000Z (almost 9 years ago)
- Last Synced: 2025-03-25T09:11:18.104Z (about 2 months ago)
- Language: JavaScript
- Size: 16.6 KB
- Stars: 34
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
jsxn
---(work in progress)
jsx notation for json trees
`npm install @threepointone/jsxn --save`
jsxn is a natural fit for describing hierarchical "trees" of nodes made of `type`/`props`/`children`, such as -
- rich, structured text
- page layouts
- configs```jsx
some inner text
...// corresponds to -
[{
type: 'carousel',
props: {
delay: 300,
animation: 'appear'
},
children: [
{
type: 'banner',
props: {
src: 'photo1.jpg'
title: 'slide 1'
},
children: [
'some inner text',
]
},{
type: 'banner',
props: {
src: 'photo2.jpg'
title: 'slide 2',
active: true
}
},
// ...
]
}]
```api
---
```jsx
import { parse } from '@threepointone/jsxn'let src = ``
console.log(parse(src))
/* ... becomes */
[{
type: 'test',
props: {
prop: 123,
o: {
x: 'abc'
}
}}]
```
differences from xml
---- jsxn has no namespaces, dtds, all that
- you can write inline json, which I think is quite nice :)
- jsxn generates regular js objects, not native xml nodes.todo
---- basic parsing - done!
- match jsx whitespace spec
- singlequotes/backticks
- quoteless json keys
- good errors