@Jaromanda X is correct- you are looking for JSON.parse. Something like this would suffice:

responseArray =  "[{"id":"blah", "type":"blah", ...}, {"id":"blah2",.... },...]"
<Item[]> JSON.parse(responseArray)

Obviously, this doesn't do any validation of the response (which is bad practice). You should ideally perform some validation of the result:

responseArray =  "[{"id":"blah", "type":"blah", ...}, {"id":"blah2",.... },...]"

var result;
try {
   itemListResponse = <Item[]>JSON.parse(responseArray);

   if(!itemListResponse.has("id") ||
      !itemListResponse.has("type") ||
      !itemListResponse.has("state")){

      throw "Invalid Item";
   }
} catch (e){

}

Or, alternatively, use a JSON Schema validator like ajv.

Answer from Derek Brown 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
August 7, 2018 -

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"}
]
🌐
Stack Overflow
stackoverflow.com › questions › 41245122 › convert-json-object-to-typescript-array
convert json object to typescript array
@Injectable() export class BootstrapService { constructor(private http: Http) {} getBootstrapInfo() { return this.http.get('api/foo') .map(response => { var responseData = response.json(); var result = []; for (let item in responseData.uiMessages) { // Create the uiMessage object here, not sure what its structure is result.push({ field: item, message: responseData.uiMessages[item] }); } return result; }); } } ... Find the answer to your question by asking.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › JSON › parse
JSON.parse() - JavaScript | MDN
Because JSON has no syntax space for annotating type metadata, in order to revive values that are not plain objects, you have to consider one of the following: Serialize the entire object to a string and prefix it with a type tag. "Guess" based on the structure of the data (for example, an ...
Find elsewhere
🌐
Boot.dev
blog.boot.dev › javascript › converting-an-array-to-json-object-in-javascript
Converting an Array to a JSON Object in JavaScript | Boot.dev
October 1, 2022 - The JSON.stringify() method converts a JavaScript object, array, or value to a JSON string.
🌐
W3Schools
w3schools.com › js › js_json_arrays.asp
JSON Arrays
In JSON, array values must be of type string, number, object, array, boolean or null. In JavaScript, array values can be all of the above, plus any other valid JavaScript expression, including functions, dates, and undefined.
🌐
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
Answer (1 of 5): Assuming you are not already receiving Json, and text instead; you can use JSON.parse() to create an object from a properly formatted json string. This can be done in Javascript/Typescript in general, and is not limited to Angular. For example (see line 6 below): [code]var xmlht...
🌐
Bguppl
bguppl.github.io › interpreters › practice_sessions › ps1.html
TypeScript: Complex Data Types, JSON, Map, Filter, Reduce | Principles of Programming Languages
We verified that this complex structure can be written into JSON, and then parsed back into an identical value (this is a round-trip that preserves the value). We can look at the type of studentData as a tree of simpler values: ... This can be made more readable if we name the types, using the type alias TypeScript construct to name map compound types:
🌐
TutorialsPoint
tutorialspoint.com › from-json-object-to-an-array-in-javascript
From JSON object to an array in JavaScript
Let's consider an example, here we are creating a JSON Object and converting it into an array by pushing all its properties into an array. Here the loop will iterate the object together with keys and values and then they will be pushed into the array.
Top answer
1 of 3
1

It would be like the following (assuming response.data is where the JSON text is).

const items: Array<{title: string, image: string}> = JSON.parse(response.data)

const sliderObjects = items.map(item =>
    new SliderObject(item['title'], item['image']))

2 of 3
0

You can come up with your own reviver and conventions in your models to support proper deserialization.

class SliderObject {
  public title: StringField;
  public image: UrlField;

  constructor(title: string, image: string) { /* class initialization */ }

  static fromJSON(data: { image: string; title: string; }): SliderObject {
    return new SliderObject(data.title, data.image);
  }
  static isDeserializableFromJSON(data: any): data is { image: string; title: string; } {
    return data && typeof(data.image) === 'string' && typeof(data.title) === 'string';
  }
}

function jsonReviver(_: string, value: unknown): unknown {
  if (SliderObject.isDeserializableFromJSON(value)) {
    return SliderObject.fromJSON(value);
  }
  return value;
}

console.log(JSON.parse(`[/* array data */]`, jsonReviver));

In the example above I have added to static methods to SliderObject to help with serialization and a custom json reviver function. The static methods detect if data create from JSON.parse can be used to create a sliderObject and the other actually creates the new class. The reviver will call the guard method and return a SliderObject if the guard passed.

There are lots ways to skin this cat. I personally eschew TypeScript classes in favor of interfaces which I find are more flexible. Why try to make TypeScript C# or Java? By using interfaces, I can largely avoid situations like these.

🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › JSON › stringify
JSON.stringify() - JavaScript | MDN
The value to convert to a JSON string. ... A function that alters the behavior of the stringification process, or an array of strings and numbers that specifies properties of value to be included in the output. If replacer is an array, all elements in this array that are not strings or numbers (either primitives or wrapper objects), including Symbol values, are completely ignored.
🌐
Python Guides
pythonguides.com › convert-json-to-array-in-typescript
How To Convert JSON To Array In TypeScript?
March 7, 2025 - First, define an interface that matches the structure of the JSON objects. This helps TypeScript understand the shape of the data and provides type-checking. interface User { id: number; name: string; email: string; } Next, use the JSON.parse method to convert the JSON string into an array ...
Top answer
1 of 1
1

Actually the shared is not a valid object. The comma is missing after every entry.

data ={aegisLab: {scan_time: 2, def_time: "2020-07-09T07:57:00Z", scan_result_i: 0, threat_found: ""},
agnitum: null,
ahnlab: {scan_time: 0, def_time: "2020-07-09T00:00:00Z", scan_result_i: 0, threat_found: ""},
avg: null,
avira: {scan_time: 0, def_time: "2020-07-09T00:00:00Z", scan_result_i: 0, threat_found: ""},
baidu: null,
bitDefender: {scan_time: 8, def_time: "2020-07-09T04:18:00Z", scan_result_i: 0, threat_found: ""},
byteHero: {scan_time: 204, def_time: "2020-07-07T00:00:00Z", scan_result_i: 0, threat_found: ""},
clamAV: {scan_time: 16, def_time: "2020-07-08T13:50:00Z", scan_result_i: 0, threat_found: ""},
cyren: {scan_time: 8, def_time: "2020-07-09T08:43:00Z", scan_result_i: 0, threat_found: ""},
drWebGateway: null,
emsisoft: {scan_time: 16, def_time: "2020-07-08T23:38:00Z", scan_result_i: 0, threat_found: ""},
eset: {scan_time: 1, def_time: "2020-07-09T00:00:00Z", scan_result_i: 0, threat_found: ""},
filseclab: {scan_time: 173, def_time: "2020-06-22T00:09:00Z", scan_result_i: 0, threat_found: ""},
fortinet: {scan_time: 17, def_time: "2020-07-08T00:00:00Z", scan_result_i: 0, threat_found: ""},
fprot: null,
fsecure: null,
hauri: {scan_time: 4, def_time: "2020-07-09T00:00:00Z", scan_result_i: 0, threat_found: ""},
ikarus: {scan_time: 9, def_time: "2020-07-09T07:45:26Z", scan_result_i: 0, threat_found: ""},
jiangmin: {scan_time: 707, def_time: "2020-07-06T19:06:00Z", scan_result_i: 0, threat_found: ""},
k7: {scan_time: 0, def_time: "2020-07-09T07:29:00Z", scan_result_i: 0, threat_found: ""},
lavasoft: null,
mcAfee: {scan_time: 1, def_time: "2020-07-08T00:00:00Z", scan_result_i: 0, threat_found: ""},
microsoftSecurityEssentials: null,
nProtect: null,
nanoav: {scan_time: 2, def_time: "2020-07-09T01:49:00Z", scan_result_i: 0, threat_found: ""},
preventon: {scan_time: 47, def_time: "2020-07-09T03:08:00Z", scan_result_i: 0, threat_found: ""},
quickHeal: null,
sophos: {scan_time: 1, def_time: "2020-07-09T03:08:00Z", scan_result_i: 0, threat_found: ""},
stoPzilla: null,
superAntiSpyware: {scan_time: 958, def_time: "2020-07-02T14:29:00Z", scan_result_i: 0, threat_found: ""},
threatTrack: null,
totalDefense: null,
trendMicro: {scan_time: 486, def_time: "2020-07-07T20:22:00Z", scan_result_i: 0, threat_found: ""},
trendMicroHouseCall: null,
virITeXplorer: null,
virusBlokAda: {scan_time: 14, def_time: "2020-07-09T08:37:00Z", scan_result_i: 0, threat_found: ""},
xvirusPersonalGuard: null,
zillya: null,
zoner: null};

public res = Object.keys(this.data).map(key => {
                    return {
                        ...this.data[key],
                      scannerName: key,

                  };
            });

So I have corrected your input first. Now it's working

CheckThis

🌐
Stack Overflow
stackoverflow.com › questions › 69854460 › convert-array-to-json-in-typescript
convert array to json in typescript - Stack Overflow
If you want to add the value field, you can manually add it first, before converting into JSON. ... let array = ['element1', 'element2', 'element3'] let arrayWithValue = array.map(el => ({value: el})); console.log(JSON.stringify(arrayWithValue));
🌐
Stack Overflow
stackoverflow.com › questions › 60446587 › how-to-convert-json-object-to-an-typescript-array-in-an-api
How to convert JSON object to an Typescript array in an api - Stack Overflow
How can I convert my Object to Array in typescript and show particular or all values. ... Handling an API response object is no different to handling any other JSON object.
🌐
JSON Editor Online
jsoneditoronline.org › home › parse › json-to-typescript
JSON to TypeScript, 4 different approaches | Indepth
December 23, 2022 - There are various ways to go about turning an unstructured JSON document into a TypeScript model. The simplest approach is to just cast the data to your model via data as User[]. This does not guarantee that the data actually contains a list ...