jsonpath-object-transform

WebJar for jsonpath-object-transform

Лицензия

Лицензия

MIT
Категории

Категории

JSON Данные JsonPath ORM
Группа

Группа

org.webjars.npm
Идентификатор

Идентификатор

jsonpath-object-transform
Последняя версия

Последняя версия

1.0.4
Дата

Дата

Тип

Тип

jar
Описание

Описание

jsonpath-object-transform
WebJar for jsonpath-object-transform
Ссылка на сайт

Ссылка на сайт

https://www.webjars.org
Система контроля версий

Система контроля версий

https://github.com/dvdln/jsonpath-object-transform

Скачать jsonpath-object-transform

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/org.webjars.npm/jsonpath-object-transform/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>jsonpath-object-transform</artifactId>
    <version>1.0.4</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/jsonpath-object-transform/
implementation 'org.webjars.npm:jsonpath-object-transform:1.0.4'
// https://jarcasting.com/artifacts/org.webjars.npm/jsonpath-object-transform/
implementation ("org.webjars.npm:jsonpath-object-transform:1.0.4")
'org.webjars.npm:jsonpath-object-transform:jar:1.0.4'
<dependency org="org.webjars.npm" name="jsonpath-object-transform" rev="1.0.4">
  <artifact name="jsonpath-object-transform" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='jsonpath-object-transform', version='1.0.4')
)
libraryDependencies += "org.webjars.npm" % "jsonpath-object-transform" % "1.0.4"
[org.webjars.npm/jsonpath-object-transform "1.0.4"]

Зависимости

compile (1)

Идентификатор библиотеки Тип Версия
org.webjars.npm : JSONPath jar [0.10.0,0.11)

Модули Проекта

Данный проект не имеет модулей.

jsonpath-object-transform

Transform an object literal using JSONPath.

npm

Pulls data from an object literal using JSONPath and generate a new objects based on a template. Each of the template's properties can pull a single property from the source data or an array of all results found by its JSONPath. When pulling an array of data you can also supply a subtemplate to transform each item in the array.

JSONPath is like XPath for JavaScript objects. To learn the syntax, read the documentation for the JSONPath package on npm and the original article by Stefan Goessner.

Usage

var transform = require('jsonpath-object-transform');

var template = {
  foo: ['$.some.crazy', {
    bar: '$.example'
  }]
};

var data = {
  some: {
    crazy: [
      {
        example: 'A'
      },
      {
        example: 'B'
      }
    ]
  }
};

var result = transform(data, template);

Result:

{
  foo: [
    {
      bar: 'A'
    },
    {
      bar: 'B'
    }
  ]
}

Method

jsonPathObjectTransform(data, template);

Where data and template are both a plain Object. Returns the transformed Object.

Template Objects

Your template will be an object literal that outlines what the resulting object should look like. Each property will contain a JSONPath String or Array depending on how many properties from the source data you want to assign to the generated object.

Pulling a Single Property

{ destination: '$.path.to.source' }

Use a String on your template property to assign a single object returned from your JSONPath. If your path returns multiple results then only the first is used.

Example

var template = {
  foo: '$.example'
};

var data = {
  example: 'bar'
};

Result:

{
  foo: 'bar'
}

Pulling an Array of Properties

{ destination: ['$.path.to.sources'] }

Use an Array containing a single String to assign all results returned from your JSONPath.

Example

var template = {
  foo: ['$..example']
};

var data = {
  a: {
    example: 'bar'
  },
  b: {
    example: 'baz'
  }
};

Result:

{
  foo: ['bar', 'baz']
}

Transform Items Returned in Array

{ destination: ['$.path.to.sources', { item: '$.item.path' }] }

Use an Array with a String and an Object to assign all results returned from your JSONPath and transform each of the objects with a subtemplate.

Example

var template = {
  foo: [$..example, {
    bar: '$.demo'
  }]
};

var data = {
  a: {
    example: {
      demo: 'baz'
    }
  },
  b: {
    example: {
      demo: 'qux'
    }
  }
};

Result:

{
  foo: [
    { bar: 'baz' },
    { bar: 'qux' }
  ]
}

Версии библиотеки

Версия
1.0.4