2011-04-13 72 views
9

嘗試使用一個lib,但得到這個錯誤...這個package.json文件需要改變以使用npm 0.3.0嗎?

npm ERR! JSON.parse Failed to parse package.json data. 
npm ERR! JSON.parse Note that package.json must be actual JSON, not 
npm ERR! JSON.parse just a JavaScript object. 
npm ERR! JSON.parse 
npm ERR! JSON.parse This changed in npm 0.3.0, and is not a bug in npm. 
npm ERR! JSON.parse Tell the package author to fix their package.json file. 

不知道什麼是可能需要改變,使其有效的JSON,非常感謝!

+0

http://jsonlint.com/ – Domenic 2013-12-12 21:22:27

+0

@fancy查看我的回答,我認爲它是最優雅的方式。你可以重置安塞? – Barun 2015-07-28 12:20:33

回答

14

有效的JSON必須同時具有引號中的對象的鍵和值。用引號括住所有的鍵,這會使錯誤消失。

參考:JSON spec

更新:我做了骯髒的工作適合你。讓我知道這是否修復它。

{ "name": "embedly" 
, "version": "0.3.2" 
, "description": "Embedly client library for node" 
, "homepage": "https://github.com/embedly/embedly-node" 
, "keywords": [] 
, "author": 
    { "name": "Bob Corsaro" 
    , "email": "[email protected]" 
    , "url": "http://www.google.com/profiles/rcorsaro" 
    } 
, "repository": 
    { "type": "git" 
    , "url": "git://github.com/embedly/embedly-node" 
    } 
, "bugs": { "web": "http://github.com/embedly/embedly-node/issues/" } 
, "directories": 
    { "doc": "./docs" 
    , "lib": "./lib" 
    , "test": "./test" 
    } 
, "dependencies": {"hashish": "", "qs": ""} 
, "devDependencies": {"vows": ">= 0.5.6"} 
, "main": "./lib/embedly.js" 
, "scripts": { "test": "vows" } 
, "bin": 
    { "embedly_oembed": "bin/embedly_oembed.js" 
    , "embedly_objectify": "bin/embedly_objectify.js" 
    , "embedly_preview": "bin/embedly_preview.js" 
    } 
} 
+4

其他常見的區別是任何字典或數組中的尾隨常見。 JSON不能有尾隨逗號。 – Erik 2013-08-24 18:14:20

+0

由於我不得不在報價單中包裹布爾值,所以這也拋出了我。這是通過http://jsonlint.com/沒有引號。 – Antfish 2015-05-14 09:36:24

5

除了@Hans恩格爾答案使用npm help json得到的應該是在的package.json文件是什麼規格

16

只是爲了完成答案,你可以簡單地使用在線JSON驗證驗證你的package.json
我強烈建議http://jsonlint.com/,將您的package.json粘貼到textarea中,然後單擊驗證按鈕,就是這樣!

+1

+100 upvotes如果我可以給 – 2015-03-21 12:43:57

+0

@SarasArya我的答案有多少upvotes? – Barun 2015-07-17 11:47:47

+0

我很推薦我驗證json對象的方式@afshin Mehrabani – Barun 2015-07-28 12:21:58

0

我已經經歷過這個問題,在我的情況下,它只是代替逗號(,)。 我已經使用點(。)。 你可以簡單地在任何JSON驗證器中打開它,它會幫助你。 其中一個JSON驗證器的鏈接如下。 http://www.bodurov.com/JsonFormatter/

8

超酷的方式來解決/驗證的package.json:

node package.json

,你有你的JSON驗證或錯誤行。

爲什麼使用jsonlint,聽起來很蹩腳。

+0

可悲的是允許一個upvote。 :p – 2015-07-20 09:01:49

0

我也收到了同樣的錯誤信息,首先運行npm package.json來檢查package.json文件中的錯誤,如果沒有的話運行npm cache clean