https://github.com/gkovacs/lson
LSON: LiveScript Object Notation Parser
https://github.com/gkovacs/lson
json livescript lson
Last synced: 12 months ago
JSON representation
LSON: LiveScript Object Notation Parser
- Host: GitHub
- URL: https://github.com/gkovacs/lson
- Owner: gkovacs
- Created: 2015-01-03T20:49:33.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2015-01-03T22:09:28.000Z (about 11 years ago)
- Last Synced: 2025-03-27T19:13:22.714Z (about 1 year ago)
- Topics: json, livescript, lson
- Language: LiveScript
- Homepage:
- Size: 145 KB
- Stars: 5
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# LSON: LiveScript Object Notation Parser
Same API as the JSON module, but for [LiveScript](http://livescript.net/) objects. Also supports CSON and JSON (since LSON is a superset of them).
Uses the LiveScript parser to do the actual parsing. Will not execute code.
## Install
npm install lson
## API
lson.parse: Given a string, returns an object.
lson.parseFile: Given a filename (extensions .lson and .json.ls are common), reads and parses it synchronously, and returns an object
lson.stringify: Given an object, returns a string (currently outputs pretty-printed JSON).
## LSON format
LSON is a superset of JSON and CSON. Here is an example:
```livescript
an_array: <[ an array of strings ]>
another_array: [
'another'
'array'
]
# we can even have comments
a_dict: {
key: 'value'
}
a_string: 'some string'
another_string: \anotherstring
```
This corresponds to the following JSON:
```javascript
{
"an_array": [
"an",
"array",
"of",
"strings"
],
"another_array": [
"another",
"array"
],
"a_dict": {
"key": "value"
},
"a_string": "some string",
"another_string": "anotherstring"
}
```
## Example
```livescript
lson = require('lson')
parsed = lson.parse('''
an_array: <[ an array of strings ]>
another_array: [
'another'
'array'
]
# we can even have comments
a_dict: {
key: 'value'
}
a_string: 'some string'
another_string: \\anotherstring
''')
console.log(lson.stringify(parsed))
```
## Licence
MIT
## Credits
Author: [Geza Kovacs](https://github.com/gkovacs)