admin管理员组文章数量:1415145
I'm new to JavaScript and JSON and I'm trying to upload my NPM package. For some reason, I get this error when I try to publish it:
Unexpected token } in JSON at position 351 while parsing near '..."license": "ISC",
},
"bugs": {
"e..."
Here's my JSON file.
{
"name": "M-P-Formulas-JS",
"version": "1.0.0",
"description": "The M-P-Formulas package for JavaScript. This package allows the user to use math and physics formulas such as the Pythagorean Theorem.",
"main": "mpformulasJS.js",
"author": {
"email": "[email protected]",
"name": "Jeff Lockhart",
"url": "",
"license": "ISC",
},
"bugs": {
"email": "[email protected]",
},
"dependencies": {
"Math": "",
},
"keywords": [
"mpformulas",
"mpformulasjs",
"m-p-formulas-js",
"math",
"physics",
"formulas",
"module",
"package",
],
}
I even ran npm cache clean
but, since it did not work, I can assure that my code is wrong. If so, how can I solve this?
Thank you.
I'm new to JavaScript and JSON and I'm trying to upload my NPM package. For some reason, I get this error when I try to publish it:
Unexpected token } in JSON at position 351 while parsing near '..."license": "ISC",
},
"bugs": {
"e..."
Here's my JSON file.
{
"name": "M-P-Formulas-JS",
"version": "1.0.0",
"description": "The M-P-Formulas package for JavaScript. This package allows the user to use math and physics formulas such as the Pythagorean Theorem.",
"main": "mpformulasJS.js",
"author": {
"email": "[email protected]",
"name": "Jeff Lockhart",
"url": "",
"license": "ISC",
},
"bugs": {
"email": "[email protected]",
},
"dependencies": {
"Math": "",
},
"keywords": [
"mpformulas",
"mpformulasjs",
"m-p-formulas-js",
"math",
"physics",
"formulas",
"module",
"package",
],
}
I even ran npm cache clean
but, since it did not work, I can assure that my code is wrong. If so, how can I solve this?
Thank you.
Share Improve this question asked Jan 2, 2018 at 15:04 Jeff LockhartJeff Lockhart 131 silver badge6 bronze badges 8- Remove the trailing ma after the keywords array. Remove every trailing ma – lleon Commented Jan 2, 2018 at 15:05
- What code is wrong? Where is your code? – Ramesh Rajendran Commented Jan 2, 2018 at 15:06
- JSON does not allow trailing mas after the last element of an array. – Joe Clay Commented Jan 2, 2018 at 15:06
- Actually, remove the trailing ma after each last line one an object or array. I can see at least 5. – jcaron Commented Jan 2, 2018 at 15:06
- All the stray trailing mas are syntax errors in JSON. – Pointy Commented Jan 2, 2018 at 15:06
3 Answers
Reset to default 3Remove the extra ma because it's the last item before closing the object. It results in an invalid JSON.
"license": "ISC", // <--- Remove this ma
"bugs": {
"email": "[email protected]", // <--- Remove this ma
}
JS objects and JSON are different. For instance, this is a valid JS object, but invalid JSON :
bugs : {
email : "[email protected]",
}
Valid JSON would be :
"bugs": {
"email": "[email protected]"
}
Remove the mas preceeding the closing braces and brackets. Use a ma only to separate elements. The last element should not have a trailing ma. Some parsers will let you get away with this but it's invalid JavaScript and JSON.
Here a tool for testing JSON formatting.
{
"name": "M-P-Formulas-JS",
"version": "1.0.0",
"description": "The M-P-Formulas package for JavaScript. This package allows the user to use math and physics formulas such as the Pythagorean Theorem.",
"main": "mpformulasJS.js",
"author": {
"email": "[email protected]",
"name": "Jeff Lockhart",
"url": "",
"license": "ISC", <-- Lose the ma.
},
"bugs": {
"email": "[email protected]", <-- Lose the ma.
},
"dependencies": {
"Math": "", <-- Lose the ma.
},
"keywords": [
"mpformulas",
"mpformulasjs",
"m-p-formulas-js",
"math",
"physics",
"formulas",
"module",
"package", <-- Lose the ma.
], <-- Lose the ma.
}
Your JSON have unwanted
,
in end of the objects. So please try this below code to remove the,
after the last item of every objects.
var xx={
"name": "M-P-Formulas-JS",
"version": "1.0.0",
"description": "The M-P-Formulas package for JavaScript. This package allows the user to use math and physics formulas such as the Pythagorean Theorem.",
"main": "mpformulasJS.js",
"author": {
"email": "[email protected]",
"name": "Jeff Lockhart",
"url": "",
"license": "ISC",
},
"bugs": {
"email": "[email protected]",
},
"dependencies": {
"Math": "",
},
"keywords": [
"mpformulas",
"mpformulasjs",
"m-p-formulas-js",
"math",
"physics",
"formulas",
"module",
"package",
],
}
var xxx=JSON.parse(JSON.stringify(xx).replace('",]','"]').replace('",}','"}'));
console.log(xxx);
本文标签:
版权声明:本文标题:javascript - unexpected token } in JSON at position 351 while parsing near '..."license": "IS 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745212566a2647975.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论