GithubHelp home page GithubHelp logo

fbibik-json's Introduction

F[嗶][嗶]k JSON

fbbk-json TravisCI Coveralls Dependency Status

Parse JSON-Object string (not normalized JSON string) into JSON object.

Installation

$ npm install fbbk-json --save

or

$ bower install fbbk-json --save

Usage

This package has only one function:

var fJSON = require("fbbk-json");
fJSON.parse(A_JSON_STRING);

BUT

This package support the JSON string that written down like a JSON object in javascript.

For example:

'{"foo": "bar","baz": true}'    <-- both JSON and fJSON are supported
'{foo: "bar",baz: true}'        <-- only fJSON supported! ٩(๑•̀ω•́๑)۶

So you can do that:

var json1 = '{,,"foo": "bar",,,"baz": true,,}';
var json2 = '{foo: \'bar\',baz: true,c:[]}';

JSON.parse(json1);              ///< SyntaxError: Unexpected token , in JSON at position 1
JSON.parse(json2);              ///< SyntaxError: Unexpected token f
fJSON.parse(json1);             ///< { foo: 'bar', baz: true }
fJSON.parse(json2);             ///< { foo: 'bar', baz: true, c: [] }   \(●´ϖ`●)/

Contribute

You're welcome to make pull requests!

「雖然我覺得不怎麼可能有人會關注我」

fbibik-json's People

Contributors

lisposter avatar xadillax avatar xgheaven avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

fbibik-json's Issues

在多级json字符串中,如果键值对包含“[,],{,}”,会发生解析错误

示例JSON 如下

{
  "level1": {
    "level2": "with character [,],{,} "
  }
}

尝试解析

fbbk.parse('{"level1": {"level2": "with character [,],{,} "}');

抛出错误

Error: Broken JSON object near {"level1": {"level2": "with character [,],{,} "}
    at parse (/Users/plusman/Desktop/dasouche/github/fbibik-json/fjson.js:235:19)
    at Object.g.parse (/Users/plusman/Desktop/dasouche/github/fbibik-json/fjson.js:280:26)
    at Object.<anonymous> (/Users/plusman/Desktop/dasouche/github/fbibik-json/test/bug.js:3:16)
    at Module._compile (module.js:435:26)
    at Object.Module._extensions..js (module.js:442:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:311:12)
    at Function.Module.runMain (module.js:467:10)
    at startup (node.js:136:18)
    at node.js:963:3

Json 字符串解析错误

引起错误的 demo

var fJSON = require("fbbk-json");
var str = JSON.stringify({"footer":{"text":"原因:错误,I'm the","linkTemporary":"" } });
fJSON.parse(str);

错误信息

node_modules/fbbk-json/fjson.js:137
    throw new Error("Broken JSON " + (str[pos] === "{" ? "object" : "array") + " body near " + body);

Cannot parse '123' json string, but {a: '123'} works fine.

Reproduct code:

const fJSON = require('fbbk-json')

console.log(fJSON.parse("{a: '123'}")) // works great
console.log(fJSON.parse("'123'")) // cannot work, an error thrown

Error Message:

TypeError: Cannot assign to read only property '0' of string ''123''
    at parse (/your/project/path/node_modules/fbbk-json/fjson.js:214:39)
    at Object.g.parse (/your/project/path/node_modules/fbbk-json/fjson.js:353:26)

Source Code:
https://github.com/XadillaX/fbibik-json/blob/master/fjson.js#L214
😂

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.