Tag: json

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” […]

JSON object value from PHP

I am using JSON in PHP, and now I need to access it from JavaScript. How do I pass a JSON object to JavaScript? <?php $array = array(“a”=>”Caucho”, “b”=>”Resin”, “c”=>”Quercus”); $json = json_encode($array); > where My.js has: showAll(){ alert(“Show All Json Objects”); // How do I get the JSON value here? } How can I […]

How to protect/Hide Javascript method or JS file from user to view

This question already has an answer here: How can I encrypt JavaScript code so that it's not decryptable? 12 answers

Multidimensional JSON structure issue

I have the following pseudo structure. [ {“product”: { “id”:”14″, “product_title”:”My Awesome Product!”, “product_desc”:”An awesome product..” } }, {“product”: { “id”:”15″, “product_title”:”My MORE Awesome Product!”, “product_desc”:”An AWESOMER product…” } } ] I am iterating it like this: $.post(‘Ajax.php’,function(res){ res = res.pop(); $.each(res,function(product){ alert(product.product_title); }); }); However, only the last product_title is being shown. It does […]

Return both JSON and HTML in AJAX call

I have a few pages with an heavy javascript usage (e.g. sorting and filtering of a dataset). The typical usage is to display a list of complex items (usually rendered as <li> with some HTML inside): the user can delete, edit or add items with specific forms. Since the items are complex, I keep an […]

“Unexpected end of input” message on response from simple POST request to node.js

I’ve written a simple node.js program to demonstrate the problem I’m running into elsewhere. Given the following node.js program: var http = require(‘http’); http.createServer(function (req, res) { // simple repro for json deserializaiton error cause by right quote character ‘’’ var json = { ‘foo’: ‘bar’s answer’ }; var write = JSON.stringify(json); res.writeHead(200, { ‘Content-Type’: […]

how to convert json values in comma separated string using javascript

I have following JSON string : {“name”:”Marine Lines”,”location_id”:3},{“name”:”Ghatkopar”,”location_id”:2}