question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Key X was undefined. Cannot pass undefined in JSON. Use null instead.

See original GitHub issue

I 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:closed
  • Created 9 years ago
  • Comments:21 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
browndp08commented, Aug 9, 2015

@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?

0reactions
katowulfcommented, Dec 30, 2015

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found