Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:APIJSON APIJSON Demo JSONResponse JS

From Leeroopedia
Knowledge Sources
Domains API_Design, Validation, Testing
Last Updated 2026-10-14 00:00 GMT

Overview

Concrete tool for parsing, validating, and comparing APIJSON HTTP response objects provided by the APIJSON Demo frontend.

Description

The JSONResponse JavaScript module defines APIJSON status codes, response keys, and provides utilities for comparing API responses against expected standards. It supports deep comparison of JSON structures with ML tolerance modes, standard updates, and code/msg extraction. It is used extensively by the APIAuto test automation UI for regression testing and response validation.

Usage

Import this module when you need to validate APIJSON response codes, compare actual vs. expected responses, or update test standards in the browser-based API testing UI.

Code Reference

Source Location

Also duplicated at static/unit/apijson/JSONResponse.js (2006 lines).

Signature

// Status code constants
const CODE_SUCCESS = 200;
const CODE_NOT_LOGGED_IN = 407;
const CODE_SERVER_ERROR = 500;
// ... more codes ...

// Key constants
const KEY_CODE = "code";
const KEY_MSG = "msg";
const KEY_ID = "id";
const KEY_COUNT = "count";
const KEY_TOTAL = "total";

var JSONResponse = {
  isSuccess: function(response),
  isExist: function(response),
  getCode: function(response),
  getMsg: function(response),
  compareResponse: function(name, standard, response, ...),
  updateFullStandard: function(standard, response, isML),
  // ...
};

Import

var JSONResponse = require("./JSONResponse");
// or via script tag in browser

I/O Contract

Inputs

Name Type Required Description
response JSONObject Yes APIJSON response object to validate
standard JSONObject No Expected response standard for comparison
isML Boolean No Whether to use ML tolerance mode for comparison
name String No Field name for recursive comparison

Outputs

Name Type Description
isSuccess() returns Boolean Whether response code is 200
isExist() returns Boolean Whether response contains data
compareResponse() returns JSONObject Diff result with add/remove/update/change details
updateFullStandard() returns JSONObject Updated standard incorporating response

Usage Examples

Validate Response

var JSONResponse = require("./JSONResponse");

var response = {
  "code": 200,
  "msg": "success",
  "User": {
    "id": 82001,
    "name": "Test"
  }
};

if (JSONResponse.isSuccess(response)) {
  console.log("Request succeeded");
}

Compare Responses

var standard = { "code": 200, "User": { "id": 82001, "name": "Test" } };
var actual = { "code": 200, "User": { "id": 82001, "name": "Updated" } };

var diff = JSONResponse.compareResponse(null, standard, actual, '', false, null, null, false);
console.log(diff);
// Shows changed fields

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment