dotnet/AspNetCore.Docs · error · Error
ko.mapping.updateFromJSON, use ko.mapping.fromJSON instead.
Error message
ko.mapping.updateFromJSON, use ko.mapping.fromJSON instead. Please note that the order of parameters is different!
What it means
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.
Source
Thrown at aspnetcore/mvc/controllers/testing/samples/3.x/TestingControllersSample/src/TestingControllersSample/wwwroot/js/knockout.mapping.js:148
return result;
} catch(e) {
mappingNesting = 0;
throw e;
}
};
exports.fromJSON = function (jsonString /*, options, target*/ ) {
var parsed = ko.utils.parseJson(jsonString);
arguments[0] = parsed;
return exports.fromJS.apply(this, arguments);
};
exports.updateFromJS = function (viewModel) {
throw new Error("ko.mapping.updateFromJS, use ko.mapping.fromJS instead. Please note that the order of parameters is different!");
};
exports.updateFromJSON = function (viewModel) {
throw new Error("ko.mapping.updateFromJSON, use ko.mapping.fromJSON instead. Please note that the order of parameters is different!");
};
exports.toJS = function (rootObject, options) {
if (!defaultOptions) exports.resetDefaultOptions();
if (arguments.length == 0) throw new Error("When calling ko.mapping.toJS, pass the object you want to convert.");
if (exports.getType(defaultOptions.ignore) !== "array") throw new Error("ko.mapping.defaultOptions().ignore should be an array.");
if (exports.getType(defaultOptions.include) !== "array") throw new Error("ko.mapping.defaultOptions().include should be an array.");
if (exports.getType(defaultOptions.copy) !== "array") throw new Error("ko.mapping.defaultOptions().copy should be an array.");
// Merge in the options used in fromJS
options = fillOptions(options, rootObject[mappingProperty]);
// We just unwrap everything at every level in the object graph
return exports.visitModel(rootObject, function (x) {
return ko.utils.unwrapObservable(x)
}, options);
};View on GitHub (pinned to c67a80103a)
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.
Example fix
// before
ko.mapping.updateFromJSON(viewModel, jsonString);
// after
ko.mapping.fromJSON(jsonString, {}, viewModel); Defensive patterns
Strategy: validation
Validate before calling
// Detect legacy call and route to the supported JSON API:
function safeFromJSON(viewModel, jsonString, options) {
return ko.mapping.fromJSON(jsonString, options || {}, viewModel);
} Type guard
function isLegacyMappingCall(name) {
return name === 'updateFromJSON' || name === 'updateFromJS';
} Try / catch
// Stubs always throw — do not catch; fix the call site.
// If you must wrap for telemetry:
try { ko.mapping.fromJSON(jsonString, {}, viewModel); }
catch (e) { /* genuine mapping error, not the deprecation stub */ } Prevention
- Ban updateFromJSON via lint rule.
- Centralize JSON mapping in one helper to avoid drift.
- When upgrading, grep both updateFromJS and updateFromJSON together.
When it happens
Trigger: Calling `ko.mapping.updateFromJSON(viewModel, jsonString)`. Any invocation at all triggers the throw because the function body is only the error.
Common situations: 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.
Related errors
- ko.mapping.updateFromJS, use ko.mapping.fromJS instead. Plea
- When calling ko.mapping.toJS, pass the object you want to co
- ko.mapping.defaultOptions().ignore should be an array.
- ko.mapping.defaultOptions().include should be an array.
- There already is an object with the key that you specified.
AI-assisted analysis of dotnet/AspNetCore.Docs@c67a80103a (2026-08-13).
Data as JSON: /api/errors/b646520c71e85a32.
Report an issue: GitHub.