How to return json Nested/Sub object from controller in mvc


Few days back, got a requirement to form a nested json object, which will update the data in the html element, through Ajax.

And In online, I could find many articles related to simple json format, whereas it was very hard for me to find an article which shows the simple example of nested json object.

So thought to write this small article and share the same with others

Brief Introduction:

Official Definition of Json:


  • JSON (JavaScript Object Notation) is a lightweight data-interchange format.
  • It is easy for humans to read and write.
  • It is easy for machines to parse and generate.


JSON is a text format that is completely language independent but uses conventions that are familiar to programmers of the C-family of languages, including C, C++, C#, Java, JavaScript, Perl, Python, and many others. These properties make JSON an ideal data-interchange language.


JsonResult Type in MVC:

JsonResult is one of the important and frequently using ActionResult Type in MVC. It has been mainly used for sending data in a json format from the controller.


Simple Nested Json Format:




In Controller:

Use this Overload of Json Method (Object, JsonRequestBehavior)

It will Creates a JsonResult object that serializes the specified object to JavaScript Object Notation (JSON) format using the specified JSON request behaviour



In client side:

Call the controller action method and for the simple and test purpose, get the value from the json and show it in the JavaScript alert like the below code:





Hope the above information was helpful, kindly let me know your thoughts or feedbacks




1,402 total views, 5 views today

Leave a Reply

Your email address will not be published. Required fields are marked *