Need help writing a table

Hello,

Can someone help me write a lua table with the following JSON data? I don’t want to decode this, I just want to see how to create a table in my app that will then be encoded to look like the JSON below.  I need to know how to take data from name and age fields and put them into a table. I can do this but I need the employees at the beginning and I do not know how to do that. 

Thanks!

{ "employees": [{ "name": "John", "Age": "10" }, { "name": "Joe", "Age": "11" }, { "name": "Jim", "Age": "12" }] }

Is this what you’re looking for? (Not sure I completely grok your question.)

local foo = {} foo.employees = { {name="John", age=10}, {name="Joe", age=11}, {name="Jim", age=12}, } for x = 1, #foo.employees do print(foo.employees[x].name) end

 Jay

Or, if you’re just wanting employees to be the variable name…

local employees = { {name="John", age=10}, {name="Joe", age=11}, {name="Jim", age=12}, } for x = 1, #employees do print(employees[x].name) end

 Jay

The first reply did exactly what I needed. In my .net code I refer to the employees field to load everything in an array after it was parsed and I can added each record from the table.

Thanks!!

Warren

Is this what you’re looking for? (Not sure I completely grok your question.)

local foo = {} foo.employees = { {name="John", age=10}, {name="Joe", age=11}, {name="Jim", age=12}, } for x = 1, #foo.employees do print(foo.employees[x].name) end

 Jay

Or, if you’re just wanting employees to be the variable name…

local employees = { {name="John", age=10}, {name="Joe", age=11}, {name="Jim", age=12}, } for x = 1, #employees do print(employees[x].name) end

 Jay

The first reply did exactly what I needed. In my .net code I refer to the employees field to load everything in an array after it was parsed and I can added each record from the table.

Thanks!!

Warren