Answer the question
In order to leave comments, you need to log in
What is the best way to parse untyped JSON?
Hello, please tell me if there is any good approach for parsing untyped JSON data?
The backend returns the JSON content as an object. The data needs to be received and parsed.
JSON is one and it is large, some of the data is needed by one component, some by others, and this data needs to be received in the component's resolver. However, every time this data is needed, it is necessary to describe the interface for each component.
Is there any solution so as not to write the same type of destructuring functions and each time not to describe the interface that is needed essentially once.
An example of the current implementation on Stackblitz
At the moment, the object is destructured and a new object is formed in accordance with the interface.
The problem is that for each router the data set is different and you have to write your own method individually for each component.
Answer the question
In order to leave comments, you need to log in
The question is not very clear, but if the problem is json typing, then Google is full of json to ts generators that will generate the necessary interfaces for you. There are also libraries that will allow you to automate this issue and runtime helpers . And, finally, if the server provides its spec in open api (swagger), there are generators that will immediately generate all the necessary body kit for you, incl. for angular.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question