</>
Skip to content
AngularJS lessons (26/28)

AngularJS — JSON

JSON Filter

<pre>{{data | json}}</pre>

Parsing JSON

// In controller
$scope.data = JSON.parse(jsonString);

Displaying JSON

<div ng-repeat="(key, value) in data">
  <strong>{{key}}:</strong> {{value}}
</div>

JSON in Services

app.factory('DataService', function($http) {
  return {
    getData: function() {
      return $http.get('/api/data').then(function(response) {
        return response.data;
      });
    },
    postData: function(data) {
      return $http.post('/api/data', data);
    }
  };
});

JSON with Forms

$scope.submitForm = function() {
  $http.post('/api/submit', $scope.formData)
    .then(function(response) {
      console.log('Success:', response.data);
    });
};

Mini Practice

  1. Display JSON data
  2. Parse JSON strings
  3. Send JSON in requests
  4. Display nested objects

Up Next

Continue with Cookies — AngularJS cookies.

Related Topics

Frequently Asked Questions about JSON

What is JSON in AngularJS?

JSON is a fundamental concept in AngularJS. This lesson explains it step by step with clear examples, making it easy for beginners to understand.

How do I learn JSON?

Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn JSON.

Why is JSON important in AngularJS?

JSON is essential for AngularJS development. Understanding this concept will help you write better code and solve real-world problems more effectively.