v 3.0.0 Unexpected token u in JSON (json parse undefined) when ../create/?someparams
See original GitHub issueSteps to reproduce:
#/resource/create?anyParams
Unexpected token u in JSON at position 0
seems json is trying to parse undefined variable
Environment
- React-admin version: 3.0.0
Issue Analytics
- State:
- Created 4 years ago
- Comments:11 (3 by maintainers)
Top Results From Across the Web
Unexpected token u in JSON at position 0 Error in JS
The "Unexpected token u in JSON at position 0" error occurs when we pass an undefined value to the JSON.parse or $.parseJSON methods....
Read more >How To Fix Unexpected token u in JSON at position 0 - Isotropic
When parsed, undefined is converted into u, which is then defined as the token in the error message of "Unexpected token u in...
Read more >uncaught syntaxerror unexpected token U JSON
That error is normally seen when the value given to JSON.parse is actually undefined . So, I would check the code that is...
Read more >Unexpected token u in JSON at position 0 - ItsJavaScript
The Unexpected token u in JSON at position 0 mainly occurs if we pass an undefined value to JSON.parse() method or $.parseJSON() method....
Read more >What Is JSON and How to Handle an “Unexpected Token” Error
Learn what JSON is and how you can deal with errors occurring when parsing JSON data, such as "Unexpected Token < in JSON...
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

I also just discovered another, seemingly more intended, way to do this:
https://github.com/marmelab/react-admin/blob/master/docs/CreateEdit.md#prefilling-a-create-record
Using
stateit’s possible to pass pre-filled data to create without using query params at all.In 3.0, the way to pre-fill some fields in the create form is to pass a stringified object as the
sourceURL parameter. That’s what theCloneButtondoes:In v2, this feature didn’t use the fields of the
sourceget parameter, but all the get parameters. This lead to hard to fix bugs like #3966.The advanced tutorials were indeed written for v2. For v3, the right syntax should be:
Sorry for not mentioning it in the UPGRADE guide - we figured that, since both the
Createpage and theCloneButtonwere changed at the same time, it was a backwards compatible change. We forgot that we had documented the inner workings ofCloneButtonin an advanced tutorial, which made it a public API.So this is a breaking change, not a bug. I’ll document it in the Upgrade guide.
Also, there is indeed a small bug:
useCreateControllershould not try to parse thesearch.sourcefield if it’s not present. I’ll also fix it in a future PR.