2017-08-04 123 views
0

我有一堆JSON文件,我得到的數據來自日期/時間段。我正在處理的大部分JSON文件都比這個大很多,但我認爲一個更小的JSON文件將更容易處理。編輯JSON - 添加屬性

{"playlists":[{"uri":"spotify:user:11130196075:playlist:1Ov4b3NkyzIMwfY9E8ixpE","listeners":366,"streams":386,"dateAdded":"2016-02-24","newListeners":327,"title":"#Covers","owner":"Saga Prommeedet"},{"uri":"spotify:user:mickeyrose30:playlist:2Ov4b3NkyzIMwfY9E8ixpE","listeners":229,"streams":263,"dateAdded":"removed","newListeners":154,"title":"bestcovers2016","owner":"Mickey Rose"}],"top":2,"total":53820} 

什麼,我基本上是試圖做的是添加日期屬性數據的每一行,所以,當我將多個文件JSON通過分析工具,以便把數據右行與​​關聯正確的日期。我首先想到的是它寫成這樣:

{"playlists":[{"uri":"spotify:user:11130196075:playlist:1Ov4b3NkyzIMwfY9E8ixpE","listeners":366,"streams":386,"dateAdded":"2016-02-24","newListeners":327,"title":"#Covers","owner":"Saga Prommeedet"},{"uri":"spotify:user:mickeyrose30:playlist:2Ov4b3NkyzIMwfY9E8ixpE","listeners":229,"streams":263,"dateAdded":"removed","newListeners":154,"title":"bestcovers2016","owner":"Mickey Rose"}],"top":2,"total":53820,"date":072617} 

因爲「頂」和「總」屬性顯示在每行數據(與關聯值也顯示出了對各行)時,我就忍了它通過像Tableau這樣的分析工具。

而且,已經編輯並通過支架保存文件,並通過該轉換器(https://konklone.io/json/

+0

你的編程語言是什麼? –

回答

0

測試的東西在JavaScript語言

var m = JSON.parse(json_string); 
m["date"]="20170804"; 
JSON.stringify(m); 

這會爲你工作,很簡單,