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": "8b21espq@gmail.com",
"name": "Jeff Lockhart",
"url": "",
"license": "ISC",
},
"bugs": {
"email": "8b21espq@gmail.com",
},
"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.
Remove the extra comma because it's the last item before closing the object. It results in an invalid JSON.
"license": "ISC", // <--- Remove this comma
"bugs": {
"email": "8b21espq@gmail.com", // <--- Remove this comma
}
JS objects and JSON are different. For instance, this is a valid JS object, but invalid JSON :
bugs : {
email : "8b21espq@gmail.com",
}
Valid JSON would be :
"bugs": {
"email": "8b21espq@gmail.com"
}
Remove the commas preceeding the closing braces and brackets. Use a comma only to separate elements. The last element should not have a trailing comma. 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": "8b21espq@gmail.com",
"name": "Jeff Lockhart",
"url": "",
"license": "ISC", <-- Lose the comma.
},
"bugs": {
"email": "8b21espq@gmail.com", <-- Lose the comma.
},
"dependencies": {
"Math": "", <-- Lose the comma.
},
"keywords": [
"mpformulas",
"mpformulasjs",
"m-p-formulas-js",
"math",
"physics",
"formulas",
"module",
"package", <-- Lose the comma.
], <-- Lose the comma.
}
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": "MP-Formulas-JS", "version": "1.0.0", "description": "The MP-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": "8b21espq@gmail.com", "name": "Jeff Lockhart", "url": "", "license": "ISC", }, "bugs": { "email": "8b21espq@gmail.com", }, "dependencies": { "Math": "", }, "keywords": [ "mpformulas", "mpformulasjs", "mp-formulas-js", "math", "physics", "formulas", "module", "package", ], } var xxx=JSON.parse(JSON.stringify(xx).replace('",]','"]').replace('",}','"}')); console.log(xxx);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.