Tag: json

String replace values recursively in json

I have a json object such as: var json = { “title”: “Math Symbols: ¬”, “sections”: [ “The ¬ symbol”, “¬ and y” ] }; I need to replace all instances of the “¬” character with something that looks like the Mathematical symbol for x: sample. Side note: I can’t use that actual symbol (html […]

Using the response from an asynchronous call with the Google Maps API

I have a .json file that I’m trying to import as a text string. This is the exact file contents: { “type”: “Polygon”, “coordinates”: [ [ [ 1.5887868, 50.8315241 ], [ 1.5830702, 50.8466931 ]……. ] ] ] } I’m trying to import it using this: jsonString = jQuery.get(‘./polygons/1.json’, function(data) { console.log(data); }); However, console.log(data) is […]

Join JSON Object member string values together

“category”: [{ “id”: 28, “name”: “Dogs” }, { “id”: 14, “name”: “Cats” }, { “id”: 878, “name”: “Sheep” }], I have the above JSON parsed (using .ajax and jsonp as callback) and I would like to join all the values of “name” into a string. i.e. “Dogs, Cats, Sheep”. How can I do this? I […]

Single quotes within json value

This question already has an answer here: How can I accommodate a string with both single and double quotes inside of it in Javascript 4 answers How to escape special characters in building a JSON string? 9 answers

How to parsing Json Array in Javascript?

Json Array as following is easy to parse, { “movieCategories”: [ “a” : “Animation”, “b” :”Romance”, “c” :”Science Fiction” “d” : “Western” ] } Now,I have a Json response as following which is stored in movies.json file. { “movieCategories”: [ “Animation”, “Romance”, “Science Fiction”, “Western” ] } I am not sure how to parse the […]

Parsing a JSON object in javascript

I have the following JSON Object: [{“id”:”123″,”username”:”test”}] I want to parse username using javascript so i did this var content = ‘[{“id”:”123″,”username”:”test”}] obj = JSON.parse(content) alert(obj.username) I get an alert: undefined I’ve tried parsing the JSON without the [ ] and it worked For example: var content = ‘{“id”:”123″,”username”:”test”}’ obj = JSON.parse(content) alert(obj.username) My question […]

Correct label syntax for JSON object

It seems there are different standards out there on labels for JSON, some want quotes around JSON object labels, some do not. Can someone tell me what the standard is? Quotes are bad camp Chrome {“label”:1111} – SyntaxError: Unexpected token : {label:1111} – Works Firefox {“label”:1111} – SyntaxError: invalid label {label:1111} – Works Quotes are […]

JSON to JSON Converting: Flattening

How can I get from data1 = [ { “label”: “Some Label”, “value”: ‘018’}, { “label”: “Another Label”, “value”: ‘020’} ] to data2 = { “018”: “Some Label”, “020”: “Another Label” } how should the for loop look like? for (let item of data){ …. }

JSON conversion in javascript

I’m trying to stringify a multi-array variable into a JSON string in Javascript. The //i’m using functions from http://www.json.org/json2.js var info = new Array(max); for (var i=0; i<max; i++) { var coordinate = [25 , 32]; info[i] = coordinate; } var result = JSON.stringify(info); But result doesn’t look like a JSON string at all. What […]

Array of JSON Objects

Good morning, I am new to JSON and am trying to re-implement a page using JSON instead of some 2-dimensional arrays. What I am hoping to accomplish is get an array of objects. The objects would look like this: { // Restaurant “location” : “123 Road Dr”, “city_state” : “MyCity ST”, “phone” : “555-555-5555”, “distance” […]