jsonicjs / jsonic Goto Github PK
View Code? Open in Web Editor NEWJSON parser that isn't strict
License: MIT License
JSON parser that isn't strict
License: MIT License
if you try to parse string:
'{ key:23 value }'
you get json
{key:'23value'} instead of {key:'23 value'}
*removes space between number (23) and text (value)
open problem... any ideas?
I'm having a problem with the stringify function.
doing such:
console.log( jsonic.stringify( {a:"bc",d:1} )
results in following output: {a:bc,d:1}
but i want it to output: {a:'bc',d:1} instead of {a:bc,d:1}. I need the quotes for my project. Can somebody please help me in how to fix it?
As the title states there cant be spaces after the property name and before the :
, unless the property is in double quotes.
If you cant fix it you should be it in your rules list.
https://github.com/rjrodger/jsonic/blob/master/jsonic.js#L2170
var omit = callopts.omit || callopts.o || {}; // should be []?
A Prototype Pollution vulnerability Affecting @jsonic/jsonic-next, due to missing check if the argument resolves to the object prototype. This allow the attacker to inject malicious object property using the built-in Object property __proto__
which recursively assigned to all the objects in the program.
Details sent directly to the maintainer
both // and /* */
foo.bar=1
=> {"foo":{"bar":1}}
I've been testing jsonic for a few minutes and discovered several issues:
JSON.parse('0')
// -> 0
JSON.parse('"a string"')
// -> 'a string'
jsonic cannot parse this, but should be compatible to JSON.
{ 0x12: 0x14 }
// -> { '18': 20 }
jsonic('{0x12:0x14}')
{ '0x12': '0x14' }
The result is not what I expected (same result as in JS). Hexadecimal numbers could be supported.
And invalid numbers like 0g12
could cause a parse error.
I don't really like that way string don't require quotes. It can confuse and it's not much work to add two quotes.
Example:
var name = 'John Doe';
var o = { name: name }
I don't need to tell what the result of js and jsonic is.
And { name: John Joe }
is not even valid JS.
Better: disable that by default, and require quotes.
If the programmer badly wants the short syntax, it could be turned on optionally.
Accidentally stumbled upon this, which is currently not allowed:
{
'test': 34
}
Guess this should be relaxed, too.
Thanks!
Currently jsonic converts `string`
to "`string`"
There seems to be some sort of issue with pegjs, - the --export-var
option of pegjs in particular.
Running $ npm run-script build
outputs a warning:
Can't use the -e/--export-var option with the "commonjs" module format.
The jsonic-parser.js
file is not being generated:
$ git status
On branch master
Your branch is up to date with 'origin/master'.nothing to commit, working tree clean
Specifying --format globals
or building without the --export-var
option remedies the problem and generates a new jsonic-parser.js
file. However, this change breaks the rest of the build
script.
{ [SyntaxError: Expected "," or "]" but "\\" found.]
message: 'Expected "," or "]" but "\\\\" found.',
expected:
[ { type: 'literal', value: ',', description: '","' },
{ type: 'literal', value: ']', description: '"]"' } ],
found: '\\',
offset: 210,
line: 1,
column: 211,
name: 'SyntaxError' }
Input was
[ '\\uC774\\uB7F0 \\uB958\\uC758 \\uB3C4\\uC11C\\uB97C \\uC88B\\uC544\\uD558\\uC9C0 \\uC54A\\uC74C\\uC5D0\\uB3C4 \\uBD88\\uAD6C\\uD558\\uACE0 \\uC774 \\uCC45\\uC744 \\uC9D1\\uC5B4\\uB4E0 \\uC774\\uC720\\uB294 \\uB2E8\\uC21C\\uD558\\uB2E4. \\',
'\\uC778\\uD130\\uD30C\\uD06C\\uB3C4\\uC11C',
'HelloET',
'20170321',
'http://book.interpark.com/blog/HelloET/4829812',
'\\uC790\\uC874\\uAC10 \\uC218\\uC5C5\\uC744 \\uC77D\\uACE0' ]
or(it might be escaped)
[ '\\uC774\\uB7F0 \\uB958\\uC758 \\uB3C4\\uC11C\\uB97C \\uC88B\\uC544\\uD558\\uC9C0 \\uC54A\\uC74C\\uC5D0\\uB3C4 \\uBD88\\uAD6C\\uD558\\uACE0 \\uC774 \\uCC45\\uC744 \\uC9D1\\uC5B4\\uB4E0 \\uC774\\uC720\\uB294 \\uB2E8\\uC21C\\uD558\\uB2E4. \\',
'\\uC778\\uD130\\uD30C\\uD06C\\uB3C4\\uC11C',
'HelloET',
'20170321',
'http://book.interpark.com/blog/HelloET/4829812',
'\\uC790\\uC874\\uAC10 \\uC218\\uC5C5\\uC744 \\uC77D\\uACE0' ]
javascript code was...(data was raw data so i should parse this like)
jsonic(`["${data.join('","')}"]`)
Input was just array that includes strings, but there is double backslash.
I guess this is caused by backslash(escaped) element in array.
using node 4.2.4 attempting to parse an array where the value of index[0] is 0 - parser drops the index and shortens the array length by 1.
Examples in node repl:
foo = '{foo:"bar", arr:[0,0]}'
'{foo:"bar", arr:[0,0]}'
jsonic(foo)
{ foo: 'bar', arr: [ 0 ] }
foo = '{foo:"bar", arr:[0,0,0]}'
'{foo:"bar", arr:[0,0,0]}'
jsonic(foo)
{ foo: 'bar', arr: [ 0, 0 ] }
foo = '{foo:"bar", arr:[0,0,1]}'
'{foo:"bar", arr:[0,0,1]}'
jsonic(foo)
{ foo: 'bar', arr: [ 0, 1 ] }
foo = '{foo:"bar", arr:[1,0,1]}'
'{foo:"bar", arr:[1,0,1]}'
jsonic(foo)
{ foo: 'bar', arr: [ 1, 0, 1 ] }
foo = '{foo:"bar", arr:[0,1,1]}'
'{foo:"bar", arr:[0,1,1]}'
jsonic(foo)
{ foo: 'bar', arr: [ 1, 1 ] }
ie you cannot use {"path":"a/b"}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.