Can a JSON be modeled with a class in TypeScript (or Angular)?
For example, I am using Firebase and have a node called /books structured like this:
books
-- 157sq561sqs1
-- author: 'Foo'
-- title: 'Hello world'
(Where 157sq561sqs1 is the book's ID)
This structure can be represented as:
157sq561sqs1 : { author: 'Foo', title:'Hello world'}
I attempted to model it using the following class:
export class Book {
id: number;
author: string;
title: string;
}
However, the output looked like this instead:
books
-- 0
-- id: 157sq561sqs1
-- author: 'Foo'
-- title: 'Hello world'
Is there a way to model it so that the desired structure is achieved?