{"record":{"id":"48a178ff56da5512","repo":"dotnet/AspNetCore.Docs","slug":"ko-mapping-updatefromjs-use-ko-mapping-fromjs-ins-48a178","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/3.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/3.x/TestingControllersSample/src/TestingControllersSample/wwwroot/js/knockout.mapping.js#L126-L162","documentation":"knockout.mapping.js throws this error unconditionally when the deprecated `ko.mapping.updateFromJS` is invoked. The function exists only to redirect callers to the replacement `ko.mapping.fromJS`. Unlike fromJS (jsObject, options, target), updateFromJS took (viewModel, ...) so the parameter order differs and silently swapping would corrupt mappings.","triggerScenarios":"Calling `ko.mapping.updateFromJS(viewModel, data)` — any call site still using the legacy update-from-JavaScript-object API. The throw is the entire function body, so even a valid invocation fails.","commonSituations":"Upgrading knockout.mapping from an older version that shipped updateFromJS; copy-pasted code from pre-2.0 tutorials; large legacy codebases where the rename was missed during a dependency bump.","solutions":["Replace `ko.mapping.updateFromJS(viewModel, data)` with `ko.mapping.fromJS(data, {}, viewModel)` — pass the JS object first, options second, and the existing viewModel as the target to update in place.","Grep the codebase for `updateFromJS` to find every stale call site and migrate each.","Pin knockout.mapping to a legacy version only if a full migration is impossible; otherwise finish the rename."],"exampleFix":"// before\nko.mapping.updateFromJS(viewModel, data);\n\n// after\nko.mapping.fromJS(data, {}, viewModel);","handlingStrategy":"validation","validationCode":"// Before calling, confirm the legacy API is not used:\nif (typeof ko.mapping.updateFromJS === 'function') {\n  console.warn('updateFromJS is a stub that throws — migrate to ko.mapping.fromJS');\n}\n// Then call the supported API:\nko.mapping.fromJS(data, {}, viewModel);","typeGuard":"function isSupportedMapping(fn) {\n  return fn !== ko.mapping.updateFromJS && fn !== ko.mapping.updateFromJSON;\n}","tryCatchPattern":"// Not recommended — these stubs always throw. Migrate instead.\ntry { ko.mapping.updateFromJS(viewModel, data); }\ncatch (e) { console.error('Migrate to ko.mapping.fromJS:', e.message); }","preventionTips":["Search the codebase for updateFromJS/updateFromJSON whenever bumping knockout.mapping.","Keep a single helper that wraps fromJS/fromJSON so call sites never reach the legacy stubs.","Add an ESLint no-restricted-syntax rule banning ko.mapping.updateFrom*."],"tags":["knockout","deprecation","mapping","javascript"],"backgroundTag":null,"analyzedSha":"c67a80103a1a74db20784debd919c7fdda96c510","analyzedAt":"2026-08-13T17:46:11.763Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}