Converts a text file into json data and outputs it.

  node.js, question

The text file format is as follows:
Beijing 2
Hebei 3
Hebei-Handan 301
Hebei-Baoding 302
Hebei-Xingtai 303
Shandong 4
Shandong-Qingdao 401
Shandong-Yantai 402

Convert to json similar to the following, I just want the result

const treeData = [{
 Label:' Hebei',
 value: '3',
 key: '3',
 children: [{
 Label:' handan',
 value: '301',
 key: '302',
 }, {
 Label:' Baoding',
 value: '302',
 key: '302',
 }],
 }]

No fault tolerance, format must follow the above format

Var str = `beijing2
 Hebei 3
 Hebei-Handan 301
 Hebei-Baoding 302
 Hebei-Xingtai 303
 Shandong 4
 Shandong-Qingdao 401
 Shandong-Yantai 402';
 var arrStr = str.split("\n");
 var result = [];
 arrStr.map(i => {
 let = item = i.split(" ");
 if (i.indexOf("-") == -1) {
 result.push({
 label: item[0],
 value: item[1],
 key: item[1],
 children: []
 })
 } else {
 let city = item[0].split("-");
 let cur = result.find(j => j.label == city[0])
 cur.children.push({
 label: city[1],
 value: item[1],
 key: item[1],
 })
 bracket
 })
 console.log(result)
 console.log(JSON.stringify(result))
[
 {"label ":"Beijing ","value ":"2 ","key ":"2 ","children ":[]},
 {"label ":"Hebei ","value ":"3 ","key ":"3 ","children ":[
 {"label ":"Handan ","value":"301","key":"301"},
 {"label ":"Baoding ","value":"302","key":"302"},
 {"label ":"Xingtai ","value":"303","key":"303"}
 ]},
 {"label ":"Shandong ","value ":"4 ","key ":"4 ","children ":[
 {"label ":"Qingdao ","value":"401","key":"401"},
 {"label ":"Yantai ","value":"402","key":"402"}
 ]}
 bracket