Just more info; if I change res => res.json() to res => res.text(), I get the json as text.
*{ "users": [ { "emailaddress": "bobsm...@somedomain.com", "firstname": "Bob", "lastname": "Smith", "userid": "bsmith" }, { "emailaddress": "tomjones @otherdomain.com", "firstname": "Tom", "lastname": "Jones", "userid": "tjones" }, { "emailaddress": "carli...@yahoo.com", "firstname": "Carlinda", "lastname": "Gonzalez", "userid": "cgonz" }, { "emailaddress": "atho...@freemail.com", "firstname": "Thomas", "lastname": "April", "userid": "athom" } ] } * On Thursday, August 20, 2020 at 10:36:42 AM UTC-5 Dale Preston wrote: > I have a flask API that returns valid JSON. The Content-Type is > application/json. I assign it to state using useEffect. When I call on > the variable returned by useEffect, I get the error: *Error: Objects are > not valid as a React child*. > > I know that React is reading the JSON because I get various details. The > JSON returns a "users" table. If I assign the JSON to a variable named > "data" and I try to use "data" I get this detail showing that the users > table was recognized. > > *Error: Objects are not valid as a React child (found: object with keys > {users}). If you meant to render a collection of children, use an array > instead. * > > If I try to call on data.users, React gives this error showing it > successfully read the elements in the JSON: > > *Error: Objects are not valid as a React child (found: object with keys > {emailaddress, firstname, lastname, userid}). If you meant to render a > collection of children, use an array instead. * > > Complete details of my scenario, including code, is on StackOverflow at > https://stackoverflow.com/questions/63498019/objects-are-not-valid-as-a-react-child-or-how-to-consume-json-in-function-reac > > Any help in figuring out how to consume JSON from an API is appreciated. > I have seen a lot of threads and articles on various sites concerning this > same error but none have helped. > > Thanks in advance. > -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description. --- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/sqlalchemy/2a6fa7f5-50a5-4401-9616-eaae2dd24ea3n%40googlegroups.com.