ERROR TypeError: "item.toJSON is not a function
See original GitHub issueI have a parent object with a collection of children object:
public class EnduserCartModel
{
...
public ICollection<ProductListModel> products {get;set;}
}
In controller :
[HttpPost("")]
... ([FromBody]EnduserModel enduserModel)
{
...
}
At the moment of sending the object from Angular to the Server I got this error: ERROR TypeError: "item.toJSON is not a function.
This error appears on this line: data["products"].push(item.toJSON());
The code is generated by NSwag Studio: 13.6.0.0 . So here the bug.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:4
- Comments:12 (1 by maintainers)
Top Results From Across the Web
getting this error " $.toJSON is not a function "
I'm trying to use jQuery and Ajax and I use this method. but I get the error $.toJSON is not a function in...
Read more >item.toJSON is not a function #8337
we're having this issue only on one service and on method of the service that is createoredit. please guide me to solve the...
Read more >command.data.toJSON is not a function : r/Discord_Bots
Been trying to figure this out but I really cant. Without the toJSON function, i get the error DiscordAPIError[50035]: Invalid Form Body.
Read more >What is the `toJSON()` Function in JavaScript?
In JavaScript, the JSON.stringify() function looks for functions named toJSON in the object being serialized. If an object has a toJSON ...
Read more >ERROR TypeError: "item.toJSON is not a function
ERROR TypeError : "item.toJSON is not a function.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hi have the same error (V. 13.5.0) but I found the problem in my case is related to a cast.
I see in debug that my object is not create from EntityDto and toJSON in not available I change with this
And toJSON is valid function
I came across this issue multiple times and the solution was to make sure that your “item” is an instance of “ProductListModel” in front-end while you’re appending this object to your array before sending it to the back end so when it calls .toJSON() in service-proxies.ts it will find .toJSON() in your object and it will not throw that exception anymore.