Get / Set JSON Value?
See original GitHub issueI’m having some issues when attempting to set and get a JSON value, currently I have some code similar to the following:
memcache.get(username, function(err, value, key) {
var query, siteCode, user, userCredentials;
if (err != null) {
winston.error("BasicAuth: Error occured when attempting to search memcache for the user, error follows: " + (util.inspect(err)));
return done(err);
}
if (value != null) {
user = value.toJSON();
if (passwordHash.verify(password, user.hashedPassword)) {
winston.info("BasicAuth: User " + username + " with siteCode " + siteCode + " successfully logged in");
return done(null, user);
} else {
return done(null, false, {
message: 'Invalid username/password combination'
});
}
}
memcache.set(username, { some: 'JSON value', with: 'A Few', arrays: [] }, function(err, success) {
if (err != null) {
winston.error("BasicAuth: Failed to store the users details in memcache, error follows: " + (util.inspect(err)));
return done(null, userDetails);
}
winston.info("BasicAuth: Successfully stored user's details in the memcache server");
winston.info("BasicAuth: User " + username + " with siteCode " + siteCode + " successfully logged in");
return done(null, {});
})
}
But when I call the get and then user = value.toJSON();
I get a zero length array!?
Issue Analytics
- State:
- Created 9 years ago
- Comments:7 (2 by maintainers)
Top Results From Across the Web
JSON Object Literals - W3Schools
JSON object literals contains key/value pairs. Keys and values are separated by a colon. Keys must be strings, and values must be a...
Read more >How to Get Value from JSON Object in Java Example
It is used to get the (JsonString)get(name). The method parses an argument name of type String whose related value is to be returned....
Read more >c# get values from json - Stack Overflow
var data = (JObject)JsonConvert.DeserializeObject(myJSON); string nameArticles= data["articles"].Value<string>(); MessageBox.
Read more >Working with JSON - Learn web development | MDN
In this article, we've given you a simple guide to using JSON in your programs, including how to create and parse JSON, and...
Read more >Access and print a specific JSON value | Documenting APIs
Getting a specific property from a JSON response object; Printing a JSON value to the page; Get the value from an array; More...
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
I’ve written a simple wrapper that handles this nicely:
@alevy I got there in the end, I realised that I needed to call
JSON.stringify
when setting and thenJSON.parse(buffer.toString())
when getting the data. But I agree, an example would have been nice! 👍