hoppscotch/hoppscotch · error · Error

JSON schema validation is not available in this environment.

Error message

JSON schema validation is not available in this environment. To use this feature, please enable the experimental scripting sandbox or upgrade to a supported version of Hoppscotch that includes JSON schema validation support.

What it means

Thrown by the `pm.expect(...).to.be.jsonSchema(schema)` BDD assertion (post-request.js:3442) when the host did not provide `inputs.validateJsonSchema`. The message instructs enabling the experimental scripting sandbox or upgrading Hoppscotch, because AJV-based validation is injected from outside the QuickJS sandbox (it cannot be bundled inside).

Source

Thrown at packages/hoppscotch-js-sandbox/src/bootstrap-code/post-request.js:3442

          responseTime: {
            below: (ms) => {
              const actual = globalThis.hopp.response.responseTime
              globalThis.hopp.expect(actual).to.be.below(ms)
            },
            above: (ms) => {
              const actual = globalThis.hopp.response.responseTime
              globalThis.hopp.expect(actual).to.be.above(ms)
            },
          },
          jsonSchema: (schema) => {
            // Manual jsonSchema validation with Postman-compatible messages
            // Delegates to external AJV-based validator provided via inputs.validateJsonSchema
            // This matches Postman's behavior: record assertion but don't throw
            const jsonData = globalThis.hopp.response.body.asJSON()

            // Validate schema
            if (!inputs.validateJsonSchema) {
              throw new Error(
                "JSON schema validation is not available in this environment. To use this feature, please enable the experimental scripting sandbox or upgrade to a supported version of Hoppscotch that includes JSON schema validation support."
              )
            }
            const validation = inputs.validateJsonSchema(jsonData, schema)

            // Record result with Postman-compatible message using helper
            if (inputs.pushExpectResult) {
              const status = validation.isValid ? "pass" : "fail"
              const message = validation.isValid
                ? "Response body matches JSON schema"
                : validation.errorMessage || "Schema validation failed"
              inputs.pushExpectResult(status, message)
            }
          },
          charset: (expectedCharset) => {
            const headers = globalThis.hopp.response.headers
            const contentType = headers.find(
              (h) => h.key.toLowerCase() === "content-type"

View on GitHub (pinned to 1acb8a3a75)

Solutions

  1. Enable the experimental scripting sandbox in Hoppscotch so the AJV validator is injected.
  2. Upgrade Hoppscotch to a version that ships JSON-schema validation support.
  3. Replace the schema assertion with manual field checks: `pm.expect(data.id).to.be.a('number')`, etc.
  4. Feature-detect before using: `if (typeof inputs !== 'undefined' && inputs.validateJsonSchema) { ... } else { /* manual */ }`.

Example fix

// before
pm.expect(pm.response.json()).to.be.jsonSchema({ type: 'object', required: ['id'] })
// after (no schema validator available)
const data = pm.response.json()
pm.expect(data).to.be.an('object')
pm.expect(data.id).to.not.be.undefined
Defensive patterns

Strategy: validation

Validate before calling

// Feature-detect before using JSON-schema assertions
function hasJsonSchemaValidator() {
  try {
    return typeof inputs !== 'undefined' && typeof inputs.validateJsonSchema === 'function'
  } catch (_) {
    return false
  }
}
if (hasJsonSchemaValidator()) {
  pm.expect(pm.response.json()).to.be.jsonSchema({ type: 'object', required: ['id'] })
} else {
  const data = pm.response.json()
  pm.expect(data).to.be.an('object')
  pm.expect(data.id).to.not.be.undefined
}

Type guard

/** True when the host injected a JSON-schema validator. */
function jsonSchemaAvailable() {
  try { return typeof inputs.validateJsonSchema === 'function' } catch (_) { return false }
}

Try / catch

try {
  pm.expect(pm.response.json()).to.be.jsonSchema(schema)
} catch (e) {
  if (e.message.startsWith('JSON schema validation is not available')) {
    console.warn('schema validator missing; enable experimental sandbox or assert manually')
  }
  throw e
}

Prevention

When it happens

Trigger: Calling `pm.expect(jsonData).to.be.jsonSchema({...})` or the `response.to.have.jsonSchema(...)` helper when the runtime inputs object lacks `validateJsonSchema`. Common when running scripts in the default (non-experimental) sandbox or an older Hoppscotch build.

Common situations: Copying a Postman collection that uses `tv4`/AJV JSON-schema assertions into Hoppscotch without enabling the experimental sandbox. CI/automated runs against a host that strips the `validateJsonSchema` input. Hoppscotch version predating the JSON-schema integration.

Related errors


AI-assisted analysis of hoppscotch/hoppscotch@1acb8a3a75 (2026-08-12). Data as JSON: /api/errors/3f3e2d8cea7a903e. Report an issue: GitHub.