TypeError: the JSON object must be str, not ‘bytes’

You just put it in the wrong order, innocent mistake. (In-depth answer). As courteously pointed out by wim, in some rare cases, they could opt for UTF-16 or UTF-32. These cases will be less common as the developers, in that scenario would be consciously deciding to throw away valuable bandwidth. So, if you run into … Read more

$(document).ready(function() is not working

Did you load jQuery in head section? Did you load it correctly? This code assumes jquery.js is in scripts directory. (You can change file name if you like) You can also use jQuery as hosted by Google: As per your comment: Apparently, your web server is not configured to return jQuery-1.6.1.js on requesting /webProject/jquery-1.6.1.js. There may be numerous reasons for this, such as wrong file … Read more

Write / add data in JSON file using Node.js

If this JSON file won’t become too big over time, you should try: Create a JavaScript object with the table array in itvar obj = { table: [] }; Add some data to it, for example:obj.table.push({id: 1, square:2}); Convert it from an object to a string with JSON.stringifyvar json = JSON.stringify(obj); Use fs to write the … Read more

Returning JSON from a PHP Script

While you’re usually fine without it, you can and should set the Content-Type header: If I’m not using a particular framework, I usually allow some request params to modify the output behavior. It can be useful, generally for quick troubleshooting, to not send a header, or sometimes print_r the data payload to eyeball it (though in most cases, it … Read more

Returning JSON from a PHP Script

While you’re usually fine without it, you can and should set the Content-Type header: If I’m not using a particular framework, I usually allow some request params to modify the output behavior. It can be useful, generally for quick troubleshooting, to not send a header, or sometimes print_r the data payload to eyeball it (though in most cases, it … Read more

How can JavaScript save to a local file?

There’s already a solution for writing file JSON online but I want to save json file locally. I’ve tried to use this example http://jsfiddle.net/RZBbY/10/ It creates a link to download the file, using this call a.attr(‘href’, ‘data:application/x-json;base64,’ + btoa(t.val())).show(); Is there a way to save the file locally instead of providing a downloadable link? There … Read more

Why do i need `typings.json` file in an Angular 2 project?

So, I’ve found this: Any JavaScript libraries, such as jQuery, the Jasmine testing library, and Angular, extend the JavaScript environment with features and syntax that the TypeScript compiler doesn’t recognize natively. When the compiler doesn’t recognize something, it throws an error. So, If we wrote a library which may use by other persons in their … Read more