An open API service indexing awesome lists of open source software.

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

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