Create class in server side as below;
[DataContract]
class MainMenu{
[DataMember]
public int id;
[DataMember]
public SubMenu[] sub;
}
[DataContract]
class SubMenu
{
[DataMember]
public string name;
[DataMember]
public string link;
[DataMember]
public SubMenu[] sub;
}
Now you need to create an array of MainMenu and populate them as per the information in the tables.
MainMenu[] oMainMenues;
Then you could return the oMainMenues as JSON object from Controller class if you use MVC.
If you want create a file anyway or want to return as customer string to form the JSon object in the client side; you could use the JSon serializer as following way.
MemoryStream stream1 = new MemoryStream();
DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(MainMenu[]));
ser.WriteObject(YourStream, oMainMenues);
You could refer to followinf article for more related information;
How to: Serialize and Deserialize JSON Data[
^]