2014-03-19 17 views
0

我有一個json文件。我想分割成不同的部分..分裂一個json文件..在大括號之間提取數據

以下是我的文件的內容。 我想基於大括號{}內容分裂,

"1010320": { 
    "abc": [ 
     "1012220", 
     "hiiiiiiiii." 
    ], 
    "xyz": "Describe" 
}, 
"1012757": { 
    "pqr": [ 
     "1013757", 
     "x" 
    ] 
}, 
"1014220": { 
    "abc": [ 
     "1018420", 
     "sooooo" 
    ], 
    "answer": "4th" 
}, 
"1019660": { 
    "abc": [ 
     "1031920", 
     "welcome" 
    ], 
    "xyz": "Describing&Interpreting" 
}, 
"1034280": { 
    "abc": [ 
     "1040560", 
     "Ok..." 
    ], 
    "nop": "Student Question" 
}, 

輸出應該是:

1)  "abc": [ 
      "1012220", 
      "hiiiiiiiii." 
     ], 
     "xyz": "Describe" 


2)   "pqr": [ 
      "1013757", 
      "x" 
     ] 


3)   "abc": [ 
      "1018420", 
      "sooooo" 
     ], 
     "answer": "4th" 

PLZ ..幫助..

+1

建議使用現有的工具,如jq,jsawk等。 – BMW

回答

0

我認爲這將是有益的你

(?<=\{)\n\s+((?:[\n]+|.*)+?)\n\} 

正則表達式演示在這裏:http://regex101.com/r/rS3wI5

+0

爲什麼在JSON解析器足夠的時候使用Regex? – andy

+0

它給出了一個錯誤...語法錯誤附近意想不到的標記'\ n \ s +((?:[\ n] + |。*)+?)\ n \}' – user1862399

+0

你怎麼使用這個正則表達式btw? – aelor