Link to home
Start Free TrialLog in
Avatar of ethar turky
ethar turkyFlag for Saudi Arabia

asked on

modification in js code

Dear all,
The code in http://jsfiddle.net/VM3jc/5/ 
assume following json string
[
	{
		"TableName": "TableName1",
		"languages": [
			{
				"name": "ID",
				"column_type": type2
			},
			{
				"name": "NameAR",
				"column_type": "type1"
			}
		]
	},
	{
		"TableName": "Tabs",
		"languages": [
			{
				"name": "FieldNameID",
				"column_type": type2
			},
			{
				"name": "FieldName02",
				"column_type": "type1"
			},
			{
				"name": "FieldName03",
				"column_type": "type1"
			}
		]
	},
	{
		"TableName": "TablName2",
		"languages": [
			{
				"name": "CustomerID",
				"column_type": type2
			},
			{
				"name": "FullName",
				"column_type": "type1"
			},
			{
				"name": "Address",
				"column_type": "type1"
			}
		]
	}
]

Open in new window


I need to modify the code to accept same json string but without "TableName" element
and add default on "TableName": "TablNameDefault"
Thanks.
Avatar of Alexandre Simões
Alexandre Simões
Flag of Switzerland image

Hi mate... Again :)

I didn't understand what you need here and how this relates to the sample.
Before you had a string and wanted to convert it to json.
Now you have json and want to do what?

Please give me an exact sample of the input and the expected output.
Avatar of ethar turky

ASKER

still,  json parser assume the string have TableName:

I need to deal with a string contains no "TableName:"
and add it ( programmatically ) to the json
can jsonfied add "TableName": "TablNameDefault" if its not shown in the string?
How do you know when a new table begins?
Now your input string is something like:
Tablename1:
FieldNameID,typ1
FieldName02,typ2
FieldName03,typ3
Tablename:
FieldNameID,typ4
FieldName02,typ1
FieldName03,typ2

Open in new window

Like this I know that each time I find something that ends with : it's a table name. If I don't have this line how do I know which fields belong to what?
if no Tablename1:
consider all as one table

if

FieldNameID,typ1
FieldName02,typ2
FieldName03,typ3
FieldNameID,typ4
FieldName02,typ1
FieldName03,typ2 

Open in new window

just treated it as :
TablNameDefault:
FieldNameID,typ1
FieldName02,typ2
FieldName03,typ3
FieldNameID,typ4
FieldName02,typ1
FieldName03,typ2 

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Alexandre Simões
Alexandre Simões
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial