-1

I'm retrieving a very large data from our API back-end. I need to convert the JSON object to a typescript object. I've tried doing JSON.parse(JSON.stringify(result)); but unfortunately, the model created from this has no methods included. How can I convert this JSON object to a typescript class? Could you please suggest any npm plugin that I can use?

result => {
      this.app = JSON.parse(JSON.stringify(result));
      resolve(true);
    }

I have a gigantic model wherein it involves nested object and polymorphism. I was hoping that I can use a npm plugin to help me

2

1 Answer 1

0

The object from JSON.parse is a plain Object.

You could create a class and use the object as an argument for the constructor and copy the properties to the new object.

You could also try using: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/setPrototypeOf

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.