You have to process the recieved response in your required format.

      findAllPersons(): Observable<Person[]> {
        return this.httpClient.get<object>('url');
      }
    
    
     findAllPersons().subscribe((response) =>{
        let array = [];
        for(let key in response){
            let p = new Person();
            p.firstName = key;
            p.lastName = response[key];
            array.push(p);
        } 
        console.log(array); // your required array
     });
Answer from khush on Stack Overflow
🌐
Reddit
reddit.com › r/angular2 › convert json file to typescript array of objects
r/Angular2 on Reddit: Convert JSON file to Typescript Array of Objects
June 26, 2020 -

I am reading in a JSON file and attempting to convert them to an array of objects. I get a syntax error on the component file.

This is the component code:

import * as blogs from '../story/stories.json';
import { IStory } from '../models/story';

@Component({
  selector: 'app-story',
  templateUrl: './story.component.html',
  styleUrls: ['./story.component.scss']
})
export class StoryComponent implements OnInit {
  stories: IStory[] ;
  constructor() { }

  ngOnInit() {
    this.stories = blogs; <-- syntax error on this line
      
  }

this is the story.ts file:

export interface IStory {
    id: number;
    author: string;
    title: string;
    pictureUrl: string;
    body: string;
  }

This is the json file, stories.json

[
{"date":3,"author":"AVC", "pictureUrl":"Scorching", "title":"Scorching", "body":"Scorching"},
{"date":4,"author":"ADF", "pictureUrl":"Scorching", "title":"Scorching", "body":"Scorching"}
]
Discussions

Convert JSON objects to JSOn array
Hi I have below data [object][object],[object][object],[object][object],[object][object]… etc So I want this all data in array format like [[object][object],[object][object],[object][object],[object][object]… etc] I used push() but it is not working. please help me. More on forum.ionicframework.com
🌐 forum.ionicframework.com
5
0
January 2, 2020
angularjs - Convert json object in to array to iterate through ng-repeat using Javascript? - Stack Overflow
Bring the best of human thought and AI automation together at your work. Explore Stack Internal ... Closed 9 years ago. Here is my sample json , i am getting my json obj from firebase i have to convert the list in to array to bind in html trough ng-repeat. More on stackoverflow.com
🌐 stackoverflow.com
angular - Angular2: converting object to an array for json file - Stack Overflow
I'm trying to load an array of objects from a JSON and display them in my template with *ngFor in my angular2 app. More on stackoverflow.com
🌐 stackoverflow.com
How to convert array to json format objects using AngularJS
Get early access and see previews of new features. Learn more about Labs ... You can run a loop on the existing object, specifying the json data for the new AngularJS object as: var data = ["Tom", "John"]; $scope.angularData = { 'nameList': [] }; angular.forEach(data, function(v, k) { $scope.angularData.nameList.push({ 'name': v }); }); Watch the demo. ... Use Array.prototype.map function to make a new array with objects. Then convert ... More on stackoverflow.com
🌐 stackoverflow.com
May 22, 2017
🌐
Quora
quora.com › How-can-I-parse-a-JSON-array-into-an-array-of-objects-in-Angular2
How to parse a JSON array into an array of objects in Angular2 - Quora
Angular (Angular 2+) uses TypeScript and HttpClient to fetch JSON; parsing a JSON array into an array of typed objects is a three-step pattern: fetch JSON, map it to TypeScript types, and (optionally) convert plain objects to class instances or validate fields.
🌐
YouTube
youtube.com › watch
Convert JSON to Array of Objects in Angular - YouTube
Learn how to easily convert JSON data into an array of objects in Angular, transforming complex data into a more usable format.---This video is based on the ...
Published: July 28, 2025
Views: 0
🌐
Ionic Framework
forum.ionicframework.com › ionic framework › ionic angular
Convert JSON objects to JSOn array - Ionic Angular - Ionic Forum
January 2, 2020 - Hi I have below data [object][object],[object][object],[object][object],[object][object]… etc So I want this all data in array format like [[object][object],[object][object],[object][object],[object][object]… etc] I used push() but it is not working. please help me.
Top answer
1 of 3
18

Use Object.keys and pass them on to Array.prototype.map to create the array that you want - see demo below:

var object={cats1:{Name:"cricket",imgUrl:"some url",list1:{bat:{Name:"bat",imgUrl:"some url",price:"$100"},pads:{displayName:"pads",imgUrl:"some url",price:"$50"}}},cats2:{Name:"football",imgUrl:"some url"}};

var result = Object.keys(object).map(e=>object[e]);

console.log(result);
.as-console-wrapper{top:0;max-height:100%!important;}

EDIT:

Correcting the solution to make list1 an array:

var object={cats1:{Name:"cricket",imgUrl:"some url",list1:{bat:{Name:"bat",imgUrl:"some url",price:"$100"},pads:{displayName:"pads",imgUrl:"some url",price:"$50"}}},cats2:{Name:"football",imgUrl:"some url"}};

var result = Object.keys(object).map(function(e){
  Object.keys(object[e]).forEach(function(k){
     if(typeof object[e][k] == "object") {
       object[e][k] = Object.keys(object[e][k]).map(function(l){
         return object[e][k][l];
       });
     }
  });
  return object[e];
});

console.log(result);
.as-console-wrapper{top:0;max-height:100%!important;}

2 of 3
3

You can recursion but do note this can cause freeze for big objects and can also lead to Maximum Call Stack exceeded

Logic

  • Loop over object and check if all entries are objects.
  • If yes, then a simple Object.keys(obj).map(x=>obj[x]) will do.
  • If not, then you will have to copy individual values and if object, then again loop in it for inner objects. A simple way is to loop on every key and if type is not object, just return value.

function ObjectToArray(obj) {
  if (typeof(obj) === 'object') {
    var keys = Object.keys(obj);
    var allObjects = keys.every(x => typeof(obj[x]) === 'object');
    if (allObjects) {
      return keys.map(x => ObjectToArray(obj[x]));
    } else {
      var o = {};
      keys.forEach(x => {
        o[x] = ObjectToArray(obj[x])
      });
      return o;
    }
  } else {
    return obj;
  }
}

var d={cats1:{Name:"cricket",imgUrl:"some url",list1:{bat:{Name:"bat",imgUrl:"some url",price:"$100"},pads:{displayName:"pads",imgUrl:"some url",price:"$50"}}},cats2:{Name:"football",imgUrl:"some url"}};

console.log(ObjectToArray(d))

🌐
Stack Overflow
stackoverflow.com › questions › 40290274 › angular2-converting-object-to-an-array-for-json-file
angular - Angular2: converting object to an array for json file - Stack Overflow
From what I understand the *ngFor will only render arrays of data and my home.component is trying to render an object of arrays. ... @Pipe({ name: 'values', pure: false }) export class ValuesPipe implements PipeTransform { transform(value: any, args: any[] = null): any { return Object.keys(value).map(key => value[key]); } }
Find elsewhere
🌐
Stack Overflow
stackoverflow.com › questions › 37805789 › how-to-convert-array-to-json-format-objects-using-angularjs
How to convert array to json format objects using AngularJS
May 22, 2017 - You can run a loop on the existing ...larData.nameList.push({ 'name': v }); }); Watch the demo. ... Use Array.prototype.map function to make a new array with objects. Then convert ......
🌐
Stack Overflow
stackoverflow.com › questions › 68456789 › how-to-convert-json-map-to-array-angular
how to convert json map to array ? Angular
July 20, 2021 - get() { this.myService.getUrl().subscribe(data => { this.myArray = Object.keys(data).map((key) => { return { id: key, name: data[key] } }): } ... Note: there is no such thing as a "JSON map".
🌐
Stack Overflow
stackoverflow.com › questions › 49185222 › angular-http-request-how-to-convert-json-object-into-an-object-array
Angular http request how to convert Json Object into an object Array - Stack Overflow
The plan is to get for example the "data2" object Array into "this.testData". I tryed different versions of http.get, but just managed to get the Json object without successfully converting it into a object[].
🌐
Coderanch
coderanch.com › t › 685196 › java › push-JSON-Object-array-AngularJs
How to push JSON Object to array in AngularJs (Web Services forum at Coderanch)
I am having an another question if I want to save this subject into my SQL database using java so what should be my approach ? ... Post it using an AJAX call to a back-end service, that will do the actual inserting. You can use a JSON or form-style request body.