{"record":{"id":"e1b879249f3bdff3","repo":"dotnet/AspNetCore.Docs","slug":"ko-mapping-updatefromjs-use-ko-mapping-fromjs-ins","errorCode":null,"errorMessage":"ko.mapping.updateFromJS, use ko.mapping.fromJS instead. Please note that the order of parameters is different!","messagePattern":"ko\\.mapping\\.updateFromJS, use ko\\.mapping\\.fromJS instead\\. Please note that the order of parameters is different!","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"aspnetcore/mvc/controllers/testing/samples/2.x/TestingControllersSample/src/TestingControllersSample/wwwroot/js/knockout.mapping.js","lineNumber":144,"sourceCode":"\n\t\t\t// Save any new mapping options in the view model, so that updateFromJS can use them later.\n\t\t\tresult[mappingProperty] = merge(result[mappingProperty], options);\n\n\t\t\treturn result;\n\t\t} catch(e) {\n\t\t\tmappingNesting = 0;\n\t\t\tthrow e;\n\t\t}\n\t};\n\n\texports.fromJSON = function (jsonString /*, options, target*/ ) {\n\t\tvar parsed = ko.utils.parseJson(jsonString);\n\t\targuments[0] = parsed;\n\t\treturn exports.fromJS.apply(this, arguments);\n\t};\n\n\texports.updateFromJS = function (viewModel) {\n\t\tthrow new Error(\"ko.mapping.updateFromJS, use ko.mapping.fromJS instead. Please note that the order of parameters is different!\");\n\t};\n\n\texports.updateFromJSON = function (viewModel) {\n\t\tthrow new Error(\"ko.mapping.updateFromJSON, use ko.mapping.fromJSON instead. Please note that the order of parameters is different!\");\n\t};\n\n\texports.toJS = function (rootObject, options) {\n\t\tif (!defaultOptions) exports.resetDefaultOptions();\n\n\t\tif (arguments.length == 0) throw new Error(\"When calling ko.mapping.toJS, pass the object you want to convert.\");\n\t\tif (exports.getType(defaultOptions.ignore) !== \"array\") throw new Error(\"ko.mapping.defaultOptions().ignore should be an array.\");\n\t\tif (exports.getType(defaultOptions.include) !== \"array\") throw new Error(\"ko.mapping.defaultOptions().include should be an array.\");\n\t\tif (exports.getType(defaultOptions.copy) !== \"array\") throw new Error(\"ko.mapping.defaultOptions().copy should be an array.\");\n\n\t\t// Merge in the options used in fromJS\n\t\toptions = fillOptions(options, rootObject[mappingProperty]);\n\n\t\t// We just unwrap everything at every level in the object graph","sourceCodeStart":126,"sourceCodeEnd":162,"githubUrl":"https://github.com/dotnet/AspNetCore.Docs/blob/c67a80103a1a74db20784debd919c7fdda96c510/aspnetcore/mvc/controllers/testing/samples/2.x/TestingControllersSample/src/TestingControllersSample/wwwroot/js/knockout.mapping.js#L126-L162","documentation":"knockout.mapping removed the old updateFromJS API and replaced it with a permanent stub that throws, directing callers to fromJS. The catch: fromJS takes parameters in a DIFFERENT order than updateFromJS did (data first, then optional target), so a blind rename silently corrupts mapping. The error message exists precisely to warn about the reordering.","triggerScenarios":"Calling ko.mapping.updateFromJS(viewModel, newData) left over from an older knockout.mapping version.","commonSituations":"Upgrading knockout.mapping from a pre-2.x plugin version; legacy codebases; copy-paste from old tutorials.","solutions":["Replace ko.mapping.updateFromJS(viewModel, newData) with ko.mapping.fromJS(newData, viewModel) — note the swapped argument order.","Update any in-place update: ko.mapping.fromJS(newData, {}, viewModel) if you also pass options.","Search the codebase for all updateFromJS usages and migrate them together."],"exampleFix":"// before\nko.mapping.updateFromJS(viewModel, newData);\n// after (arguments swapped!)\nko.mapping.fromJS(newData, viewModel);","handlingStrategy":"validation","validationCode":"// Wrapper that maps the legacy updateFromJS call onto the new API with correct order.\nfunction updateFromJSCompat(viewModel, newData) {\n  if (arguments.length < 2) {\n    throw new TypeError('updateFromJS(viewModel, newData) requires both args');\n  }\n  return ko.mapping.fromJS(newData, viewModel); // NOTE swapped order\n}","typeGuard":"function isMappedViewModel(vm) {\n  return vm != null && ko.isObservable(vm) && vm[mappingProperty] === true;\n}","tryCatchPattern":"// Prefer compile-time removal; this catch only aids migration diagnostics.\ntry {\n  ko.mapping.updateFromJS(viewModel, newData);\n} catch (e) {\n  if (/use ko.mapping.fromJS instead/.test(e.message)) {\n    console.error('Deprecated API: rewrite as ko.mapping.fromJS(newData, viewModel)');\n    ko.mapping.fromJS(newData, viewModel);\n  } else { throw e; }\n}","preventionTips":["Grep the codebase for updateFromJS/updateFromJSON during any knockout.mapping upgrade.","Remember the argument order is SWAPPED in the new fromJS/fromJSON.","Migrate all sibling calls at once and delete the wrapper once clean."],"tags":["knockout","knockout-mapping","deprecated","migration","breaking-change"],"backgroundTag":null,"analyzedSha":"c67a80103a1a74db20784debd919c7fdda96c510","analyzedAt":"2026-08-13T17:46:11.763Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}