Search Results

Search found 4865 results on 195 pages for 'json'.

Page 5/195 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • How do you deal with the conflict between ActiveSupport::JSON and the JSON gem?

    - by Luke Francl
    I am stumped with this problem. ActiveSupport::JSON defines to_json on various core objects and so does the JSON gem. However, the implementation is not the same -- the ActiveSupport version takes arguments and the JSON gem version doesn't. I installed a gem that required the JSON gem and my app broke. The issue is that I'm using to_json in a controller that returns a list of objects, but I want to control which attributes are returned. When code anywhere in my system does require 'json' I get this error message: TypeError: wrong argument type Hash (expected Data) I tried a couple of things that I read online to fix it, but nothing worked. I ended up re-writing the gem to use ActiveSupport::JSON.decode instead of JSON.parse. This works but it's not sustainable...I can't be forking gems every time I want to use a gem that requires the JSON gem. Update: The best solution of this problem is to upgrade to Rails 2.3 or higher, which fixed it.

    Read the article

  • How to assert/unit-test servers JSON response?

    - by shazax
    My current project uses JSON as data interchange format. Both Front-end and Back-end team agree upon a JSON structure before start integrating a service. At times due to un-notified changes in JSON structure by back-end team; it breaks the front-end code. Is there any external library that we could use to compare a mock JSON (fixture) with servers JSON response. Basically it should assert the whole JSON object and should throw an error if there is any violation in servers JSON format. Additional info: App is built on JQuery consuming REST JSON services.

    Read the article

  • Reading multiple json values with php

    - by jason
    I am trying to read certain values from a json string in php, I am able to do a simple json string with only one value such as $json = '{"value":"somevalue"}'; Using this: <?php $json = '{"value":"somevalue"}'; $obj = json_decode(json_encode($json)); print $obj->{'value'}; ?> But when i try an get a value from the following json string it throws an error... $json = '{"field": "title","rule": {"required": "true","minlength": "4","maxlength": "150" }}'; I validated the json on JSONlint but not sure how to access the values within this with php. Thanks

    Read the article

  • How to deserialize JSON text into a date type using Windows 8 JSON.parse?

    - by canderso
    I'm building a Windows 8 Metro app (aka "Modern UI Style" or "Windows Store app") in HTML5/JavaScript consuming JSON Web Services and I'm bumping into the following issue: in which format should my JSON Web Services serialize dates for the Windows 8 Metro JSON.parse method to deserialize those in a date type? I tried: sending dates using the ISO-8601 format, (JSON.parse returns a string), sending dates such as "/Date(1198908717056)/" as explained here (same result). I'm starting to doubt that Windows 8's JSON.parse method supports dates as even when parsing the output of its own JSON.stringify method does not return a date type. Example: var d = new Date(); // => a new date var str = JSON.stringify(d); // str is a string => "\"2012-07-10T14:44:00.000Z\"" var date2 = JSON.parse(str); // date2 is a string => "2012-07-10T14:44:00.000Z"

    Read the article

  • How can I put double quotes inside a string within an ajax JSON response from php?

    - by karlthorwald
    I receive a JSON response in an Ajax request from the server. This way it works: { "a" = "1", "b" = "hello 'kitty'" } But I did not succeed in putting double quotes around kitty. When I convert " to \x22 in the Ajax response, it is still interpreted as " by JavaScript and I cannot parse the JSON. Should I also escape the \ and unescape later (which would be possible)? How to do this? Edit: I am not sure if i expressed it well: I want this string inside of "b" after the parse: hello "kitty" If necessary I could also add an additional step after the parse to convert "b", but I guess it is not necessary, there is a more elegant way so this happens automatically? Edit2: The ajax page is generated by php. I tried several things now to create the value of b, all result in JSON parse error on the page: $b = 'hello "kitty"'; // no 1: //$b = str_replace('"',"\x22",$b); // or no 2: // $b = addslashes($b); // or no 3: //$b = str_replace('"','\"',$b); // or no 4: $b = str_replace('"','\\"',$b); echo '"b" : "' . $b . '"';

    Read the article

  • RHEL json gem installation requires make?

    - by Salahuddin559
    When I try to install json gem (gem install json), at first it fails to do so, because of some dev package issue. After fixing it, it fails saying that "sh: make: command not found" and "ERROR: Error installing json: ERROR: Failed to build gem native extension.". Why is it failing on make? Notice this is not Mac, this is in RHEL 5 (4 or 5, not sure). Why is it not able to do some "build gem native extension"?

    Read the article

  • Emacs xkcd installation needs JSON 1.4, not found in ELPA

    - by CodeKingPlusPlus
    I tried to install the xkcd emacs package (where you can view an xkcd comic in emacs) and got the following error: Need JSON 1.4, but only 1.2 is available I tried to get JSON 1.4 but I cannot find it in the package manager ELPA. It also says that I have JSON 1.3 built in and installed. A lot of things seem to not work correctly. How can I get xkcd to work inside of emacs? I use Ubuntu 12.04 and Emacs 24.3.

    Read the article

  • Can JSON be made easily and safely editable by the non-technical Excel crowd?

    - by glitch
    I'm looking for a data storage format that's very intuitive and easy to edit. It should be ideally targeted towards the same crowd as Excel. At the same time I would like the data structure to be a tree. Ideally this would be JSON, since it offers both the tree aspect and allows for more interesting constructs like arrays. That and parsing libraries for JSON are ubiquitous, so I don't have to reinvent the wheel. The problem is that, at least with a non-specialized text editor, JSON is a giant pain to edit for a non-technical user. I'm thinking along the lines of someone who might have used Excel in the past, but never a real text editor. Someone who might not be comfortable with the idea of preserving JSON syntax by hand. Are there data formats out there that would fit this profile? I'd very much prefer this to be a JSON actually, but then it would require a solid editing tool that would hide the underlying implementation from the user. Think Excel and how it abstracts CSV syntax from the user. The reason I'm looking for something like this is because the team has been working with pretty hierarchical data for a while now and we've hit the limits of how easy it is to represent in simple CSVs without having to create complex rules for how represent hierarchy semantics from each row. Any suggestions?

    Read the article

  • Is the escaping provided by the Google-Gson library enough to ensure a safe JSON payload?

    - by Lifetime_Learner
    I am currently using the Google-Gson library to convert Java objects into JSON inside a web service. Once the object has been converted to JSON, it is returned to the client to be converted into a JSON object using the JavaScript eval() function. Is the character escaping provided by the Gson library enough to ensure that nothing nasty will happen when I run the eval() function on the JSON payload? Do I need to HTML Encode the Strings in the Java Objects before passing them to the Gson library? Are there any other security concerns that I should be aware of?

    Read the article

  • C++ JSON parser

    - by pollux
    Dear reader, I'm working on a twitter client which uses the twitter streaming json api. Twitter advices JSON as XML version is deprecated. I'm looking for a good JSON parser which can parse the json data below. I'm receiving this JSON which I want to be able to read/parse using a JSON parser. { "in_reply_to_status_id": null, "text": "Home-plate umpire Crawford gets stung http://tinyurl.com/27ujc86", "favorited": false, "coordinates": null, "in_reply_to_user_id": null, "source": "<a href=\"http://apiwiki.twitter.com/\" rel=\"nofollow\">API</a>", "geo": null, "created_at": "Fri Jun 18 15:12:06 +0000 2010", "place": null, "user": { "profile_text_color": "333333", "screen_name": "HostingViral", "time_zone": "Pacific Time (US & Canada)", "url": "http://bit.ly/1Way7P", "profile_link_color": "228235", "profile_background_image_url": "http://s.twimg.com/a/1276654401/images/themes/theme14/bg.gif", "description": "Full time Internet Marketer - Helping other reach their Goals\r\nhttp://wavemarker.com", "statuses_count": 1944, "profile_sidebar_fill_color": "c7b7c7", "profile_background_tile": true, "contributors_enabled": false, "lang": "en", "notifications": null, "created_at": "Wed Dec 30 07:50:52 +0000 2009", "profile_sidebar_border_color": "120412", "following": null, "geo_enabled": false, "followers_count": 2485, "protected": false, "friends_count": 2495, "location": "Working at Home", "name": "Johnathan Thomas", "verified": false, "profile_background_color": "131516", "profile_image_url": "http://a1.twimg.com/profile_images/600114776/nessykalvo421_normal.jpg", "id": 100439873, "utc_offset": -28800, "favourites_count": 0 }, "in_reply_to_screen_name": null, "id": 16477056501, "contributors": null, "truncated": false } *This is the raw string (above it beautified) * {"in_reply_to_status_id":null,"text":"Home-plate umpire Crawford gets stung http://tinyurl.com/27ujc86","favorited":false,"coordinates":null,"in_reply_to_user_id":null,"source":"<a href=\"http://apiwiki.twitter.com/\" rel=\"nofollow\">API</a>","geo":null,"created_at":"Fri Jun 18 15:12:06 +0000 2010","place":null,"user":{"profile_text_color":"333333","screen_name":"HostingViral","time_zone":"Pacific Time (US & Canada)","url":"http://bit.ly/1Way7P","profile_link_color":"228235","profile_background_image_url":"http://s.twimg.com/a/1276654401/images/themes/theme14/bg.gif","description":"Full time Internet Marketer - Helping other reach their Goals\r\nhttp://wavemarker.com","statuses_count":1944,"profile_sidebar_fill_color":"c7b7c7","profile_background_tile":true,"contributors_enabled":false,"lang":"en","notifications":null,"created_at":"Wed Dec 30 07:50:52 +0000 2009","profile_sidebar_border_color":"120412","following":null,"geo_enabled":false,"followers_count":2485,"protected":false,"friends_count":2495,"location":"Working at Home","name":"Johnathan Thomas","verified":false,"profile_background_color":"131516","profile_image_url":"http://a1.twimg.com/profile_images/600114776/nessykalvo421_normal.jpg","id":100439873,"utc_offset":-28800,"favourites_count":0},"in_reply_to_screen_name":null,"id":16477056501,"contributors":null,"truncated":false} I've tried multiple JSON parsers from json.org though I've tried 4 now and can't find one which can parse above json. Kind regards, Pollux

    Read the article

  • accessing parsed JSON on the iPhone SDK

    - by itai alter
    Hello All! I've been following the great tutorial about (iPhone, json and Flickr API and I did manage to access the parsed json info just fine. Now I'm trying to do the same thing with the Twitter API, and I am able to get the json info and parse it, but I can't seem to access it like in Flickr. I noticed that the json info that is retrieved from Twitter is a little different from Flickr. The Flickr json info starts straight with a curly braces ({), while the Twitter json info starts with a square bracket and then a curly braces ([{). I understand that it means it's an array inside the json info, but I don't know how to access it. In the Flickr example, I access the objects like so (the second line takes the number of pages Flickr has reported): NSDictionary *results = [jsonString JSONValue]; pagesString = [[results objectForKey:@"photos"] objectForKey:@"pages"]; but I can't seem to access the Twitter response in the same way... Does anyone know of a solution? (here's an example of the Twitter JSON response: api.twitter.com/1/statuses/public_timeline.json ) Thanks a bunch!

    Read the article

  • binding nested json object value to a form field

    - by Jack
    I am building a dynamic form to edit data in a json object. First, if something like this exists let me know. I would rather not build it but I have searched many times for a tool and have found only tree like structures that require entering quotes. I would be happy to treat all values as strings. This edit functionality is for end users so it needs to be easy an not intimidating. So far I have code that generates nested tables to represent a json object. For each value I display a form field. I would like to bind the form field to the associated nested json value. If I could store a reference to the json value I would build an array of references to each value in a json object tree. I have not found a way to do that with javascript. My last resort approach will be to traverse the table after edits are made. I would rather have dynamic updates but a single submit would be better than nothing. Any ideas? // the json in files nests only a few levels. Here is the format of a simple case, { "researcherid_id":{ "id_key":"researcherid_id", "description":"Use to retrieve bibliometric data", "url_template" :[ { "name": "Author Detail", "url": "http://www.researcherid.com/rid/${key}" } ] } } $.get('file.json',make_json_form); function make_json_form(response) { dataset = $.secureEvalJSON(response); // iterate through the object and generate form field for string values. } // Then after the form is edited I want to display the raw updated json (then I want to save it but that is for another thread) // now I iterate through the form and construct the json object // I would rather have the dataset object var updated on focus out after each edit. function show_json(form_id){ var r = {}; var el = document.getElementById(form_id); table_to_json(r,el,null); $('body').html(formattedJSON(r)); }

    Read the article

  • How can I put double quotes inside a string within an ajax JSON response?

    - by karlthorwald
    I receive a JSON response in an Ajax request from the server. This way it works: { "a" = "1", "b" = "hello 'kitty'" } But I did not succeed in putting double quotes around kitty. When I convert " to \x22 in the Ajax response, it is still interpreted as " by JavaScript and I cannot parse the JSON. Should I also escape the \ and unescape later (which would be possible)? How to do this? Edit: I am not sure if i expressed it well: I want this string inside of "b" after the parse: hello "kitty" If necessary I could also add an additional step after the parse to convert "b", but I guess it is not necessary, there is a more elegant way so this happens automatically?

    Read the article

  • Not able to get the data from the JSON in OpenSocial App!

    - by Abhishek
    I have follwing JSON: {"mykey":[{name:"Jak",interests:"movies"}]} and following opensocial app code: <script type="text/os-template" require="mykey"> <ul> <li repeat="${mykey}"> <span>Offer id: ${Cur.name}</span> <span>Offer: ${Cur.interests}</span> </li> </ul> </script> but the App is not able to get the data from the JSON? Not able to find out the issue!

    Read the article

  • jquery json null when using localhost

    - by Eeyore
    I am trying to load json generated by my django app. It works when I save the json output and load it from a static file. However, when I make a call to a server it returns null. JSON {"users": [ { "id": 1, "name": "arnold" }, { "id": 2, "name": "frankie" } ]} Ajax call $.ajax({ url: "http://localhost:8000/json", //vs. json.js dataType: 'json', type: 'get', timeout: 20000, error: function() { alert("error"); }, beforeSend: function() { alert("beforeSend"); }, complete: function() { alert("complete"); }, success: function(data) { alert(data.users[0].name); } }); view.py return HttpResponse(simplejson.dumps(data), content_type = 'application/json; charset=utf8')

    Read the article

  • Sanitize json input to a java server

    - by morgancodes
    I'm using json to pass data between the browser and a java server. I'm using Json-lib to convert between java objects and json. I'd like to strip out susupicious looking stuff (i.e "doSomethingNasty().) from the user input while converting from json to java. I can imagine several points at which I could do this: I could examine the raw json string and strip out funny-looking stuff I could look for a way to intercept every json value on its way into the java object, and look for funny stuff there. I could traverse my new java objects immediately after reconstitution from json, look for any fields that are Strings, and stripp stuff out there. What's the best approach? Are there any technologies built for this this task that I tack tack on to what I have already?

    Read the article

  • Load JSON in Python as header character set

    - by mridang
    Hi everyone, I've always found character sets and encodings complicated to understand and here I'm faced with another problem. My apologies for any inaccuracies. I'll do my best. I'm requesting data from a server which returns JSON. In the HTTP headers it also returns the character set like so: Content-Type: text/html; charset=UTF-8 I'm using the JSON library in Python to load the JSON using the json.loads method. When I pass it the returned JSON, it gives me a dictionary in Unicode. I've Googled around and I know that JSON should return Unicode as JavaScript strings are Unicode objects. How can I load the JSON as UTF-8? I would like to use the same encoding as specified in the response header. I've read this post but it didn't help. Thank you.

    Read the article

  • Load JSON in Python as header chracterset

    - by mridang
    Hi everyone, I've always found character-sets and encodings complicated to understand and here I'm faced with another problem. My apologies for any inaccuracies. I'll do my best. I'm requesting data from a server which returns JSON. In the HTTP headers it also returns the character.set like so: Content-Type: text/html; charset=UTF-8 I'm using the JSON library in python to load the JSON using the json.loads method. When I pass it the returned JSON, it gives me a dictionary in Unicode. I've Googled around and I know that JSON should return Unicode as JavaScript strings are Unicode objects. How can I load the JSON as UTF-8. I would like to use the same encoding as specified in the response header. I've read this post but it didn't help. Thank you.

    Read the article

  • How can I construct and parse a JSON string in Scala / Lift

    - by David Carlson
    I am using JsonResponse to send some JSON to the client. To test that I am sending the correct response it seemed natural to me to parse the resulting JSON and validate against a data structure rather than comparing substrings. But for some reason I am unable to parse the JSON I just constructed: def tryToParse = { val jsObj :JsObj = JsObj(("foo", "bar")); // 1) val jsObjStr :String = jsObj.toJsCmd // 2) jsObjStr is: "{'foo': 'bar'}" val result = JSON.parseFull(jsObjStr) // 3) result is: None // the problem seems to be caused by the quotes: val works = JSON.parseFull("{\"foo\" : \"bar\"}") // 4) result is: Some(Map(foo -> bar)) val doesntWork = JSON.parseFull("{'foo' : 'bar'}") // 5) result is: None } How do I programmatically construct a valid JSON message in Scala/Lift that can also be parsed again?

    Read the article

  • jQuery, ajax request doesn't success with JSON on IE

    - by sylouuu
    I made an AJAX call and it works on FF & Chrome but not on IE 7-8-9. I'm loading a JSON file from my domain: $.ajax({ url: 'js/jquery.desobbcode.json', dataType: 'json', cache: false, success: function(json) { alert('ok'); }, error: function(xhr, errorString, exception) { alert("xhr.status="+xhr.status+" error="+errorString+" exception="+exception); } }); I also tried by adding contentType: 'application/json' but I receive the same output which is : xhr.status=200 error=parsererror exception=SyntaxError Unterminated string constant I checked my JSON file with JSONLint and it's OK. I checked if there is an extra comma and the content is also trimmed. See my JSON file If I put dataType: 'text', I receive the OK alert but a debug popup too. Could you help me? Regards.

    Read the article

  • What are good CLI tools for JSON?

    - by jasonmp85
    General Problem Though I may be diagnosing the root cause of an event, determining how many users it affected, or distilling timing logs in order to assess the performance and throughput impact of a recent code change, my tools stay the same: grep, awk, sed, tr, uniq, sort, zcat, tail, head, join, and split. To glue them all together, Unix gives us pipes, and for fancier filtering we have xargs. If these fail me, there's always perl -e. These tools are perfect for processing CSV files, tab-delimited files, log files with a predictable line format, or files with comma-separated key-value pairs. In other words, files where each line has next to no context. XML Analogues I recently needed to trawl through Gigabytes of XML to build a histogram of usage by user. This was easy enough with the tools I had, but for more complicated queries the normal approaches break down. Say I have files with items like this: <foo user="me"> <baz key="zoidberg" value="squid" /> <baz key="leela" value="cyclops" /> <baz key="fry" value="rube" /> </foo> And let's say I want to produce a mapping from user to average number of <baz>s per <foo>. Processing line-by-line is no longer an option: I need to know which user's <foo> I'm currently inspecting so I know whose average to update. Any sort of Unix one liner that accomplishes this task is likely to be inscrutable. Fortunately in XML-land, we have wonderful technologies like XPath, XQuery, and XSLT to help us. Previously, I had gotten accustomed to using the wonderful XML::XPath Perl module to accomplish queries like the one above, but after finding a TextMate Plugin that could run an XPath expression against my current window, I stopped writing one-off Perl scripts to query XML. And I just found out about XMLStarlet which is installing as I type this and which I look forward to using in the future. JSON Solutions? So this leads me to my question: are there any tools like this for JSON? It's only a matter of time before some investigation task requires me to do similar queries on JSON files, and without tools like XPath and XSLT, such a task will be a lot harder. If I had a bunch of JSON that looked like this: { "firstName": "Bender", "lastName": "Robot", "age": 200, "address": { "streetAddress": "123", "city": "New York", "state": "NY", "postalCode": "1729" }, "phoneNumber": [ { "type": "home", "number": "666 555-1234" }, { "type": "fax", "number": "666 555-4567" } ] } And wanted to find the average number of phone numbers each person had, I could do something like this with XPath: fn:avg(/fn:count(phoneNumber)) Questions Are there any command-line tools that can "query" JSON files in this way? If you have to process a bunch of JSON files on a Unix command line, what tools do you use? Heck, is there even work being done to make a query language like this for JSON? If you do use tools like this in your day-to-day work, what do you like/dislike about them? Are there any gotchas? I'm noticing more and more data serialization is being done using JSON, so processing tools like this will be crucial when analyzing large data dumps in the future. Language libraries for JSON are very strong and it's easy enough to write scripts to do this sort of processing, but to really let people play around with the data shell tools are needed. Related Questions Grep and Sed Equivalent for XML Command Line Processing Is there a query language for JSON? JSONPath or other XPath like utility for JSON/Javascript; or Jquery JSON

    Read the article

  • DECODING JSON CODE! HOW TO?

    - by ilnur777
    Hi, everybody! Could I ask you to help me to decode this JSON code: $json = '{"inbox":[{"from":"55512351","date":"29\/03\/2010","time":"21:24:10","utcOffsetSeconds":3600,"recipients":[{"address":"55512351","name":"55512351","deliveryStatus":"notRequested"}],"body":"This is message text."},{"from":"55512351","date":"29\/03\/2010","time":"21:24:12","utcOffsetSeconds":3600,"recipients":[{"address":"55512351","name":"55512351","deliveryStatus":"notRequested"}],"body":"This is message text."},{"from":"55512351","date":"29\/03\/2010","time":"21:24:13","utcOffsetSeconds":3600,"recipients":[{"address":"55512351","name":"55512351","deliveryStatus":"notRequested"}],"body":"This is message text."},{"from":"55512351","date":"29\/03\/2010","time":"21:24:13","utcOffsetSeconds":3600,"recipients":[{"address":"55512351","name":"55512351","deliveryStatus":"notRequested"}],"body":"This is message text."}]}'; I would like to organize above structure to this: Note 1: Folder: inbox From (from): ... Date (date): ... Time (time): ... utcOffsetSeconds: ... Recepient (address): ... Recepient (name): ... Status (deliveryStatus): ... Text (body): ... Note 2: ... Thank you in advance!

    Read the article

  • Grails JSON array

    - by armandino
    I'm converting a list of Foo objects to a JSON string. I need to parse the JSON string back into a list of Foos. However in the following example, parsing gives me a list of JSONObjects instead of Foos. Example List list = [new Foo("first"), new Foo("second")] def jsonString = (list as JSON).toString() List parsedList = JSON.parse(jsonString) as List println parsedList[0].getClass() // org.codehaus.groovy.grails.web.json.JSONObject How can I parse it into Foos instead? Thanks in advance.

    Read the article

  • JSON.parse string with quotes

    - by mjsilva
    Hi, I've this: JSON.parse('{"130.00000001":{"p_cod":"130.00000001","value":"130.00000001 HDD Upgrade to 2x 250GB HDD 2.5\" SATA2 7200rpm"}}'); http://www.jsonlint.com/ says it's perfectly valid json. But on execution I have a JSON.parse error. But, if I change my code to: JSON.parse('{"130.00000001":{"p_cod":"130.00000001","value":"130.00000001 HDD Upgrade to 2x 250GB HDD 2.5\\" SATA2 7200rpm"}}'); (note the double backslash) It works, but now jsonlint gives me invalid json :/ Can someone help to understand this behavior?

    Read the article

  • Sending and Parsing JSON in Android

    - by primal
    Hi, In the application I am developing, I would like to send messages in the form of JSON objects to a Django Server and parse the JSON response from the server and populate a custom listview. From the little JSON knowledge I have, I thought this format for the response from server { "post": { "username": "someusername", "message": "this is a sweet message", "image": "http://localhost/someimage.jpg", "time": "present time" }, } How much knowledge of JSON should I have to accomplish this purpose? Also it would be great if someone could provide me links of some tutorials for sending and parsing JSON Objects.

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >