Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
KnockoutJS Web Development

You're reading from  KnockoutJS Web Development

Product type Book
Published in Feb 2015
Publisher
ISBN-13 9781782161028
Pages 178 pages
Edition 1st Edition
Languages

JSON done Knockout style


JSON is the famous data packaging standard that seems to have taken over the Internet. At one time there was XML; RoR has its own packaging standard; and even Adobe had perhaps the best performing way to package and deliver data between the client and the server called Action Message Format (AMF). The overall winner seems to be JSON because it is simple and based on the most common development platform of all: JavaScript. If you would like more information about JSON you can visit http://json.org.

To serve our purpose, let's create a file called, json.html. The first thing we will do is convert a ViewModel to JSON. Most modern browsers have a function called JSON.stringify but that is not how we do it in Knockout. There are two methods included in Knockout:

  • ko.toJS

  • ko.toJSON

The first method, ko.toJS, will clone the Knockout data into a plain copy that contains no Knockout-related hints or information. The second method, ko.toJSON, will perform the ko.toJS action...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}