score:0
Forgive me, I didn't read all of your code, but are you sure that's the JSON response? My Spidey sense says that since <
is often the first character of an HTML or XML response, maybe that's what you're getting. Are you sure that's not being returned?
score:0
If you mean to return a JSON content-type, the easiest way is to leverage the dedicated method of the response in Express:
router.get('/test', function(req, res){
knex.select('*').from('test')
.then(data => res.json(data)) // <-- note the "json"
})
However, the JSON data you show on the post aren't valid: it misses the colon ":" character as separator between key (i.e. "RowDataPacket") and the value (i.e. the braces).
More likely, should be this:
[
RowDataPacket: { id: 1, name: 'test' },
RowDataPacket: { id: 2, name: 'test1' },
RowDataPacket: { id: 3, name: 'test2' },
RowDataPacket: { id: 4, name: 'test3' },
RowDataPacket: { id: 5, name: 'test4' },
RowDataPacket: { id: 6, name: 'test5' }
]
Source: stackoverflow.com
Related Query
- SyntaxError Unexpected token < in JSON at position 0 in react.js API navigation
- SyntaxError: Unexpected token < in JSON at position 0 API GET
- Fetch API calls fail after implementing catch-all express routing solution: Unexpected token < in JSON at position 0
- SyntaxError: Unexpected token < in JSON at position 0 - React app in Rails API
- Fetch API React Js Unexpected token < in JSON at position 0
- Fetch API in React for JSON file: Uncaught (in promise) SyntaxError: Unexpected token � in JSON at position 0
- Uncaught (in promise) SyntaxError: Unexpected token < in JSON at position 0 only on get request page
- "SyntaxError: Unexpected token < in JSON at position 0"
- React Js: Uncaught (in promise) SyntaxError: Unexpected token < in JSON at position 0
- Module parse failed: Unexpected token m in JSON at position 0
- Network error: Unexpected token < in JSON at position 0 at new ApolloError
- Next.js:FetchError: invalid json response body Unexpected token < in JSON at position 0
- Fetching JSON returns error Uncaught (in promise) SyntaxError: Unexpected token < in JSON at position 0 and status code 304: Not Modified
- How to fix “Uncaught (in promise) SyntaxError: Unexpected token < in JSON at position 0” ERROR
- Uncaught (in promise) SyntaxError: Unexpected token < in JSON at position 0
- How to fix "Uncaught (in promise) SyntaxError: Unexpected token < in JSON at position 0" ERROR
- I have an error with my jsconfig.json in react js says throw err Unexpected token } in JSON at position
- SyntaxError: Unexpected Token P in JSON at position 0 - Error in React.js app
- SyntaxError: Unexpected token m in JSON at position 0: Jest fails running tests all of a sudden
- VM1661:1 Uncaught (in promise) SyntaxError: Unexpected token s in JSON at position 0
- react : Unhandled Rejection (SyntaxError): Unexpected token < in JSON at position 0
- CANNOT POST /auth/is-verify - Unexpected token < in JSON at position 0
- Unexpected token i in JSON at position 6 - react redux app
- VM892:1 Uncaught SyntaxError: Unexpected token e in JSON at position 0
- Configure production environment in a create-react-app(SyntaxError: Unexpected token < in JSON at position 0)
- FetchError: invalid json response body at .. Unexpected token < in JSON at position 0
- Uncaught (in promise) Error: Network error: Unexpected token < in JSON at position 3
- Uncaught (in promise) SyntaxError: Unexpected token < in JSON at position 0 while acess static files in node server
- Error while deploying Next.js on vercel: Unexpected token R in JSON at position 0
- NextJS - Unexpected token < in JSON at position 0
More Query from same tag
- Stop react-select from expanding as options are added
- How to fix / clear react-select while using formik?
- concatenation jsx with Link doesn't work
- React setState called multiple times on the same state object
- Using Hooks + Callbacks
- React: Using parent to pass data between sibling components
- How to use webpack with create-react-app?
- Hashrouter always redirecting to index
- React child is not updating after after parent state changed
- React Hook Forms How to pass the errors as a props using Typescript
- Inserting JSON File Data into React Bootstrap Table 2
- Preserve space in React rendered element
- React - onChange event / setState
- React - how to make only one increment function setState multiple variables?
- Cross-Origin Request Blocked erroring out after adding application/json
- Different ways to import files in React
- Google's sign in button resizes after loading
- Retrieve other item properties too, after executing array.map
- How to pass selected items data to another component React
- How to post http request in component and update it?
- Version JS files in react
- Simplest way to use onClick to render <img> in React?
- How to change style attribute of element with React Hooks?
- Unhandled promise rejection TypeError
- setState inside useEffect is not working after i refresh the page?
- How to decide when to rerender in React
- Value from Selector doesn't work with Formik and Yup validation
- React url changes but component state the same
- Animate table rows with react
- Simulate change for textarea Jest test