gabrielcsapo / gabrielcsapo/json-ex
User input can inject functions into the JSON file
- Dominant language
- JavaScript
- Stars
- 2
- Forks
- 2
- PR merge metrics
- No merged PRs in 30d
Description
It'd be better if the syntax was a little different in my opinion. For example:
```
{
"someString":"\"hello world\"",
"someFunction":"function(){console.log(\"hello world\")}",
"someRegex":"/^R(e[gx]){2}/",
"someInt":"10",
"someFloat":"10.25",
"someBuffer":"new Buffer(\"hi\")",
"someDate":"new Date(\"10/20/2017\")"
}
```
To parse the following JSON-Ex object you could do:
```js
function parse(s){
var rObj = {};
var tObj = JSON.parse(s)
for (var property in tObj) {
if (tObj.hasOwnProperty(property)) {
rObj[property] = eval(tObj[property]);
}
}
return tObj
}
```
The returned object should equivalent to (if I am not mistaken (untested)):
```
{
someString:"hello world",
someFunction:function(){console.log("hello world")},
someRegex:/^R(e[gx]){2}/,
someInt:10,
someFloat:10.25,
someBuffer:new Buffer("hi"),
someDate:new Date("10/20/2017")
}
```
For JSON objects with sub objects. E.G.
```
{
"someObject": {
"someString":"\"hello world\""
}
}
```
You would have to make a special case that when an object is intersected, you recursively call the parser function.
In general though I think this will make a much more flexible system.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.