Key X was undefined. Cannot pass undefined in JSON. Use null instead.
See original GitHub issueI get this error when I delete all the text in the input field. It seems that when the input field is empty, the property “name” on the object “user” is set to undefined instead of null.
View:
<input type="text" ng-model="user.name">
Controller:
var firebaseio = new Firebase(FIREBASE_URL);
$firebase(firebaseio.child(USER_PATH)).$asObject().$bindTo($scope, "user");
So, how can I set it to null when the input field is cleared?
Issue Analytics
- State:
- Created 9 years ago
- Comments:21 (4 by maintainers)
Top Results From Across the Web
"Reason: `undefined` cannot be serialized as JSON. ...
a` returned from `getServerSideProps` in "/test". Reason: `undefined` cannot be serialized as JSON. Please use `null` or omit this value all together. Error: ......
Read more >How to fix undefined` cannot be serialized as JSON. ...
i am trying to fetch some data from an api using getStaticProps with next js. It returns the error undefined ...
Read more >JSON methods, toJSON
The function will be called for every (key, value) pair and should return the “replaced” value, which will be used instead of the...
Read more >JSON Object Examples: Stringify and Parse Methods ...
Let's make a list of all JSON-unsafe values and anything that isn't on the list can be considered JSON-safe. JSON-unsafe values: * undefined...
Read more >Handling JSON null and empty arrays and objects
Handling null and empty arrays and objects used in JSON data is described. JSON data has the concept of null and empty arrays...
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 FreeTop 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
Top GitHub Comments
@semeano after applying novalidate to the form element, I’m still getting an error. You can see the same result on my jsfiddle at https://jsfiddle.net/kkwo9h5n/6/. Any suggestions on how else I can validate a required field and make firebase work?
Firebase/JSON do not accept undefined values in the data. ng-model also will not set values to undefined; however, if you have not declared a value for a $scope field, it can certainly be undefined.
If you attempt to place an undefined value into an AngularFire sync object/array, it’s going to create an error. This is working as intended.
Further “I have the same problem” or +1’s to this post will be deleted. Enough discussion.