Skip to main content

All Questions

Tagged with
1382 votes
23 answers
1.8m views

Convert JS object to JSON string

If I defined an object in JS with: var j={"name":"binchen"}; How can I convert the object to JSON? The output string should be: '{"name":"binchen"}'
Bin Chen's user avatar
  • 62.8k
473 votes
8 answers
432k views

Reverse of JSON.stringify?

I'm stringyfing an object like {'foo': 'bar'} How can I turn the string back to an object?
thelolcat's user avatar
  • 11.4k
324 votes
21 answers
1.7m views

Adding elements to object

I need to populate a json file, now I have something like this: {"element":{"id":10,"quantity":1}} And I need to add another "element". My first step is putting that json in a Object type using cart ...
HypeZ's user avatar
  • 4,107
320 votes
15 answers
623k views

How to get object length [duplicate]

Is there any built-in function that can return the length of an object? For example, I have a = { 'a':1,'b':2,'c':3 } which should return 3. If I use a.length it returns undefined. It could be a ...
Eugene - AmberPixels's user avatar
301 votes
11 answers
1.1m views

Converting Java objects to JSON with Jackson

I want my JSON to look like this: { "information": [{ "timestamp": "xxxx", "feature": "xxxx", "ean": 1234, "data": "xxxx" }, { "timestamp": "yyy", ...
JustTheAverageGirl's user avatar
232 votes
5 answers
303k views

Which characters are valid/invalid in a JSON key name?

Are there any forbidden characters in key names, for JavaScript objects or JSON strings? Or characters that need to be escaped? To be more specific, I'd like to use "$", "-" and space in key names.
Christophe's user avatar
  • 27.9k
218 votes
16 answers
283k views

Parse JSON String into a Particular Object Prototype in JavaScript

I know how to parse a JSON String and turn it into a JavaScript Object. You can use JSON.parse() in modern browsers (and IE9+). That's great, but how can I take that JavaScript Object and turn it ...
BMiner's user avatar
  • 16.9k
218 votes
10 answers
65k views

Multiple arguments vs. options object

When creating a JavaScript function with multiple arguments, I am always confronted with this choice: pass a list of arguments vs. pass an options object. For example I am writing a function to map a ...
Christophe's user avatar
  • 27.9k
167 votes
20 answers
592k views

Convert object string to JSON

How can I convert a string that describes an object into a JSON string using JavaScript (or jQuery)? e.g: Convert this (NOT a valid JSON string): var str = "{ hello: 'world', places: ['Africa', '...
snorpey's user avatar
  • 2,327
141 votes
9 answers
104k views

Determine whether JSON is a JSONObject or JSONArray

I am going to receive either a JSON Object or Array from server, but I have no idea which it will be. I need to work with the JSON, but to do so, I need to know if it is an Object or an Array. I am ...
Greg's user avatar
  • 3,100
128 votes
9 answers
203k views

Difference between JSON object and JSON array

After having a short look at Google I found this link that describes the difference between a JSON object and a JSON array, yet from a syntax point of view. When would one be used over the other in a ...
Luke Taylor's user avatar
  • 9,541
113 votes
17 answers
307k views

Get specific object by id from array of objects in AngularJS

I have a JSON file containing some data I d like to access on my AngularJS website. Now what I want is to get only one object from the array. So I d like for example Item with id 1. The data looks ...
mooonli's user avatar
  • 2,373
112 votes
13 answers
234k views

How can I check if a value is a JSON object?

My server side code returns a value which is a JSON object on success and a string 'false' on failure. Now how can I check whether the returned value is a JSON object?
bart's user avatar
  • 15.2k
105 votes
15 answers
112k views

gson.toJson() throws StackOverflowError

I would like to generate a JSON String from my object: Gson gson = new Gson(); String json = gson.toJson(item); Everytime I try to do this, I get this error: 14:46:40,236 ERROR [[BomItemToJSON]] ...
nimrod's user avatar
  • 5,682
105 votes
11 answers
174k views

Serializing PHP object to JSON

So I was wandering around php.net for information about serializing PHP objects to JSON, when I stumbled across the new JsonSerializable Interface. It's only PHP >= 5.4 though, and I'm running in a 5....
Dan Lugg's user avatar
  • 20.5k

15 30 50 per page
1
2 3 4 5
326