Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9252165
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:52:34+00:00 2026-06-18T10:52:34+00:00

I wish to save my view model to a database as a JSON string.

  • 0

I wish to save my view model to a database as a JSON string. The idea is that I can then re-load my view model by reading the JSON back and using the direct approach to load my view model’s data:

From the Knockout documentation:

// Load and parse the JSON
var someJSON = /* Omitted: fetch it from the server however you want */;
var parsed = JSON.parse(someJSON);

// Update view model properties
viewModel.firstName(parsed.firstName);
viewModel.pets(parsed.pets);

That all works great but where I’ve already initialised my model and I’m simply updating it with one that I’ve already saved, I can’t see how I can select the originally selected entry in the array’s drop-down list.

To put it another way, the pets drop-down list is selected as “Cat” when I save my model. I then change the drop-down list selection to “Dog”. On re-loading the saved model, I need my drop-down list selection to be reset to “Cat”.

I’m a bit concerned about this because I have some arrays of objects which also need to be read in from the saved model and it’s looking like it’s going to be very difficult to do.

Any ideas or suggestions are welcome 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T10:52:35+00:00Added an answer on June 18, 2026 at 10:52 am

    What you are looking for is the mapping plugin for Knockout. http://knockoutjs.com/documentation/plugins-mapping.html

    It has methods that handle both JSON to observables and back.

    So in your example you could do:

    var viewModel = ko.mapping.fromJSON(someJSON);
    

    And when you’re ready to go back to the server:

    var jsonData = ko.mapping.toJSON(viewModel);
    

    There are also object literal helpers if you need that (ko.mapping.toJS & ko.mapping.fromJS)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

PEAR's HTTP_Request2 - I've got a HTTP_Request2_CookieJar object that I wish to save for
This code below is using the FWRITE function. however i wish to save the
I wonder if anyone can help, i wish to save a variable globally for
I have PictureDrawable that I wish to save as an image (JPEG/PNG) but I
I have a simple save file dialog that I wish to use as a
I have a Google Map on my View. I wish to save the long
I have a model (share) in which I save who can edit a lesson.
I wish to save some semantic information about data in a table. How can
I am using SQL Server Management Studio. I wish to save the results of
I've an object model I'm persisting to a SQL Compact database using EF 4.2.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.