---
title: "Parsing a Message in JavaScript using JSON"  
description: "This article is going to explain on how to parse a message in JavaScript using JSON. We can parse the message with JSON in JavaScript by using the met"  
author: "Anonymous User"  
published: 2012-05-08  
updated: 2019-09-07  
canonical: https://www.mindstick.com/articles/940/parsing-a-message-in-javascript-using-json  
category: "json"  
tags: ["json"]  
reading_time: 2 minutes  

---

# Parsing a Message in JavaScript using JSON

This [article](https://yourviews.mindstick.com/view/81489/kashmir-now-after-an-year-of-abrogation-of-article-370) is going to [explain](https://www.mindstick.com/forum/159699/what-is-a-compilation-error-in-dot-net-core-explain-with-an-example) on how to parse a [message](https://www.mindstick.com/interview/682/which-are-the-various-message-map-macros) in [JavaScript](https://www.mindstick.com/articles/874/how-to-create-watermark-text-for-textbox-by-using-javascript) using JSON. We can parse the message with JSON in JavaScript by using the method String.parseJSON(filter). It parses the JSON message to a string or object. The [parameter](https://www.mindstick.com/blog/450/parameter-class-in-c-sharp) filter is [optional](https://www.mindstick.com/interview/22851/main-difference-between-optional-and-required-keywords) in this method which is used to filter message or [transform](https://www.mindstick.com/interview/511/what-are-the-steps-to-transform-xml-into-html-using-xsl) their results. This method internally uses the JavaScript's method eval() to parse messages.\

To understand the Message [Parsing](https://www.mindstick.com/forum/33918/how-to-parsing-a-json-file-with-c-sharp-mvc) in JavaScript using JSON writes down the following line of code.

```
<html><head><title>JSON Message Parsing With Example</title><script language="javascript" src="json2.js"></script><script language="javascript" >                var StudentsDetails = {            ////Decalration of array to collect record of Student.                   // Information of MCA students                        "MCAStudent": [{                         "StudentName": "Kumar Vishu",                         "Roll_No":100,                         "Stream": "Computer Science",                         "Course": "MCA"                    },                       {                         "StudentName": "Tarun Bindra",                         "Roll_No":101,                         "Stream": "Science",                         "Course": "B.Tech"                    }            ]                               }                                // Printing all array values                    var i=0                    var dataCollection = new Array();                    for(i=0;i<StudentsDetails.MCAStudent.length;i++)                    {                                 // Push the data into array                            dataCollection.push(StudentsDetails.MCAStudent[i].StudentName);                            dataCollection.push(StudentsDetails.MCAStudent[i].Roll_No);                            dataCollection.push(StudentsDetails.MCAStudent[i].Stream);                            dataCollection.push(StudentsDetails.MCAStudent[i].Course);                    }                                                                                             alert("Welcome to JSON Message Example ");                           // Use toJSONString() function for message parsing                           alert(dataCollection.toJSONString());</script></head><body>Message parsing successfully in JavaScript using JSON.</body></html>
```

\

Now save the above code in html format (Here I’m saving this file with ***‘JSONParsing.html’*** ) and [execute](https://www.mindstick.com/interview/49/how-can-i-execute-a-php-script-using-command-line) with [web browser](https://answers.mindstick.com/qa/95505/what-are-the-pros-and-cons-of-using-safari-web-browser).

![Parsing a Message in JavaScript using JSON](https://www.mindstick.com/mindstickarticle/ec2506c6-c50a-44dc-911d-9f17144edb22/images/c5c4d02e-679e-4a9f-a2b1-0663e98d01c8.png)

Now click on button ***‘Ok’*** after that parsed message will be display in alert message box.

![Parsing a Message in JavaScript using JSON](https://www.mindstick.com/mindstickarticle/ec2506c6-c50a-44dc-911d-9f17144edb22/images/9f5015af-7c52-4df1-81b4-94067bee0d1d.png)

Highlighted area; showing the parse message in alert message box. Now click on button ‘Ok’.

![Parsing a Message in JavaScript using JSON](https://www.mindstick.com/mindstickarticle/ec2506c6-c50a-44dc-911d-9f17144edb22/images/9734e36e-eca1-4af4-b1ae-a2a4813908b3.png)

This is the complete description on ***Parsing a Message in JavaScript using JSON***.

\

---

Original Source: https://www.mindstick.com/articles/940/parsing-a-message-in-javascript-using-json

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
