{"record":{"id":"b646520c71e85a32","repo":"dotnet/AspNetCore.Docs","slug":"ko-mapping-updatefromjson-use-ko-mapping-fromjson-b64652","errorCode":null,"errorMessage":"ko.mapping.updateFromJSON, use ko.mapping.fromJSON instead. Please note that the order of parameters is different!","messagePattern":"ko\\.mapping\\.updateFromJSON, use ko\\.mapping\\.fromJSON 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":148,"sourceCode":"\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\n\t\treturn exports.visitModel(rootObject, function (x) {\n\t\t\treturn ko.utils.unwrapObservable(x)\n\t\t}, options);\n\t};","sourceCodeStart":130,"sourceCodeEnd":166,"githubUrl":"https://github.com/dotnet/AspNetCore.Docs/blob/c67a80103a1a74db20784debd919c7fdda96c510/aspnetcore/mvc/controllers/testing/samples/3.x/TestingControllersSample/src/TestingControllersSample/wwwroot/js/knockout.mapping.js#L130-L166","documentation":"knockout.mapping.js throws this unconditionally when the deprecated `ko.mapping.updateFromJSON` is called. It is the JSON-string counterpart of updateFromJS and exists solely to push callers to `ko.mapping.fromJSON`, which has a different parameter order.","triggerScenarios":"Calling `ko.mapping.updateFromJSON(viewModel, jsonString)`. Any invocation at all triggers the throw because the function body is only the error.","commonSituations":"Legacy code that received JSON strings from an AJAX endpoint and used the old update API; partial migration where updateFromJS was renamed but the JSON variant was missed.","solutions":["Replace `ko.mapping.updateFromJSON(viewModel, jsonString)` with `ko.mapping.fromJSON(jsonString, {}, viewModel)` — JSON string first, then options, then the target viewModel.","Search the project for `updateFromJSON` and migrate every occurrence.","If you only have a JS object, prefer fromJS; only use fromJSON when the input is an unparsed JSON string."],"exampleFix":"// before\nko.mapping.updateFromJSON(viewModel, jsonString);\n\n// after\nko.mapping.fromJSON(jsonString, {}, viewModel);","handlingStrategy":"validation","validationCode":"// Detect legacy call and route to the supported JSON API:\nfunction safeFromJSON(viewModel, jsonString, options) {\n  return ko.mapping.fromJSON(jsonString, options || {}, viewModel);\n}","typeGuard":"function isLegacyMappingCall(name) {\n  return name === 'updateFromJSON' || name === 'updateFromJS';\n}","tryCatchPattern":"// Stubs always throw — do not catch; fix the call site.\n// If you must wrap for telemetry:\ntry { ko.mapping.fromJSON(jsonString, {}, viewModel); }\ncatch (e) { /* genuine mapping error, not the deprecation stub */ }","preventionTips":["Ban updateFromJSON via lint rule.","Centralize JSON mapping in one helper to avoid drift.","When upgrading, grep both updateFromJS and updateFromJSON together."],"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"}