ethar turky
asked on
Generate Json using JS
Deal all,
The following code generate json
I just need to change the js code to pares this data:
The following code generate json
var jsonfied = [{
items : items.replace(/,$/, "").split("\n").map(function(item) {
var values = item.split(',');
return {
name : values[0],
column_type: values[1]
};
})
}];
to parse this data :FieldName01,typ1
FieldName02,typ2
FieldName03,typ3
I just need to change the js code to pares this data:
Tablename1:
FieldNameID,typ1
FieldName02,typ2
FieldName03,typ3
Tablename2:
FieldNameID,typ4
FieldName02,typ1
FieldName03,typ2
and generate the following json:[{
TableName: "TableName1" ,
languages: [
{ name: "FieldNameID" , column_type:"typ1" },
{ name: "FieldName02" , column_type:"typ2" },
{ name: "FieldName03" , column_type:"typ3" },
],
},
{
TableName: "TableName2" ,
languages: [
{ name: "FieldNameID" , column_type:"typ4" },
{ name: "FieldName02" , column_type:"typ1" },
{ name: "FieldName03" , column_type:"typ2" },
]
}]
ASKER
what is the useful of input here?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
ok, I just need to add [ and ] for whole result string ?
ASKER
please follow with this question:
https://www.experts-exchange.com/questions/28272801/modification-in-js-code.html
https://www.experts-exchange.com/questions/28272801/modification-in-js-code.html
This time I didn't do it with the map because there's no way to properly split by the table name row.
So what I do is split by line and create a new item each time I find a line that ends with :
Open in new window