JSON Model-to-Model Projection (JM2MP) Documentation

JSON Model-to-Model Projection (JM2MP) Documentation

Module

jm2mp/index

This module implements the evaluation process of the projection language JM2MP and exposes it as a public API.

It exports:

  • Hierarchy of errors.

  • Pipeline: resolve, normalizeModule, validateModule, evaluate.

  • Loaders: string, file, and URL.

  • Query adapters: interfaces/contracts, individual factories, and registry's factory.

  • High level functionality: project links all stages.

    The native QueryAdapter is always available; the external references (jsonpath, jsonata, jsonquery, jsonpointer, and jmespath) are dynamically loaded on demand.

Source

Methods

static

createAdapterRegistry(defaultAdaptersToLoadopt, …otherAdaptersToLoad) → {Promise.<AdapterRegistry>}

It creates an adapter registry with the query adapters specified by the caller.

The native query adapter is always included automatically; it requires no external dependencies.

It combines two ways to add adapters:

  1. Adapters predefined by the library: these are enabled using Boolean flags in the defaultAdaptersToLoad parameter. Their libraries are dynamically imported when enabled, so the cost is zero if they are not used.

  2. Custom adapters: these are passed as rest arguments after the first parameter; each one can be a pre-constructed QueryAdapter instance object or a factory function (synchronous or asynchronous) that returns an actual QueryAdapter instance.

Parameters

  • defaultAdaptersToLoad object <optional>

    Properties

    • jsonpath boolean <optional>
      false

      It registers the intention to use the JSONPath query language (and imports the jsonpath-plus package).

    • jsonata boolean <optional>
      false

      It registers the intention to use the JSONata query language (and imports the jsonata package).

    • jsonataOptions object <optional>

      It configures the options for createJsonataAdapter (timeout, ...).

    • jsonquery boolean <optional>
      false

      It registers the intention to use the JSON Query query language (and imports the @jsonquerylang/jsonquery package).

    • jsonpointer boolean <optional>
      false

      It registers the intention to use the JSON Pointer / RFC 6901 query language (and imports the json-pointer package).

    • jmespath boolean <optional>
      false

      It registers the intention to use the JMESPath query language (and imports the jmespath package).

  • otherAdaptersToLoad QueryAdapter | function <repeatable>

    It registers the intention to use additional QueryAdapters, allowing both factory functions or already created objects.

Returns

Example

// native only:
const r1 = await createAdapterRegistry();

// Native + JSONata (with timeout):
const r2 = await createAdapterRegistry({
  jsonata: true,
  jsonataOptions: { timeout: 5000 }
});

// Native + JSONPath + JSON Pointer + JMESPath:
const r3 = await createAdapterRegistry({
  jsonpath: true,
  jsonpointer: true,
  jmespath: true,
});

 // Native + another customized adapter:
const myAdapter = await createAnotherAdapter();
const r4 = await createAdapterRegistry({}, myAdapter);

Throws

Whenever a package cannot be imported.

Type
module:jm2mp/errors.AdapterError

Source

static

project(params) → {Promise.<*>}

The high level convenience function: resolves, validates, and evaluates.

It chains the three stages together in a safe order.

This is the recommended approach for standard usage.

Parameters

  • params object

    Properties

    • rootName string

      The name for the root projection module.

    • loader AsyncLoaderFunction

      The loader of projection modules.

    • document *

      The source JSON document to project (transform).

    • registry AdapterRegistry <optional>

      Si se omite, se crea uno con sólo el adaptador nativo.

    • options object <optional>

      Properties

      • maxDepth number <optional>
        1000

        Maximum logical depth (to avoid infinite recursion, for example).

      • maxModules number <optional>
        1000

        Maximum number of loaded projection modules.

Returns

  • Promise.<*>

    The resultant JSON document obtained.

Source

Type Definitions

AsyncLoaderFunction()

typedef {(name: string) => Promise} AsyncLoaderFunction

Source

Copyright © 2026 Luis María CÁMARA ROSSI.
Trademark ™ Copyright © 2026 Universidad Nacional de Educación a Distancia (U.N.E.D.).
The JM2MP syntax and this library JM2MP.JS are licensed under BSD-3-Clause [1] [2] license.
See LICENSE.txt for more info.

Documentation generated using JSDoc 3.6.11 and tidy-jsdoc 1.4.1 on 2026-08-26T15:45:19.728Z