Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

awesome-json2json

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

awesome-json2json - npm Package Compare versions

Comparing version 0.3.0 to 0.3.1

2

lib/index.d.ts
import { Template, IJson2jsonOptions } from './Json2json';
export default function json2json<T>(json: any, template: Template<T>, options: IJson2jsonOptions): any;
export default function json2json<T>(json: any, template: Template<T>, options?: IJson2jsonOptions): any;
export { Template, IJson2jsonOptions };

@@ -5,2 +5,3 @@ "use strict";

function json2json(json, template, options) {
if (options === void 0) { options = {}; }
var mapper = new Json2json_1.default(template, options);

@@ -7,0 +8,0 @@ return mapper.map(json);

{
"name": "awesome-json2json",
"version": "0.3.0",
"version": "0.3.1",
"description": "An awesome json to json mapper",

@@ -5,0 +5,0 @@ "main": "./lib/index.js",

@@ -27,3 +27,3 @@ # Awesome json2json

Template is the structure of your output json, the rule of how to map one json data to another. The syntax should look like this:
Template is the structure of our output json, and the rule of how to map one json data to another. The syntax should look like this:

@@ -92,2 +92,4 @@ ```js

Optional chaining is a [stage-1 ECMAScript feature](https://github.com/tc39/proposal-optional-chaining), by adding a `?` to the end of one pathItem, it will return `undefined` if the value is `undefined`. As a comparison, it will throw an error without optional chaining question mark.
```js

@@ -102,2 +104,4 @@ json2json({ foo: { bar: { baz: 1 }}}, {

By passing a function to the template, the field value will be the return value of the funtion. The first argument of the function is the root of current input json.
```js

@@ -114,2 +118,4 @@ json2json({ foo: { bar: { baz: 1 }}}, {

We can combine the above two type of templates into one template item by passing an object to it, with key `$path` and `$formatting`, in this case, the first argument of `$formatting` is the json result which gets from `$path`.
```js

@@ -129,2 +135,4 @@ json2json({ foo: { bar: { baz: 1 }}}, {

If we pass some keys that are not starts with `$`, then it will return the new structure that contains the keys we pass.
```js

@@ -142,2 +150,4 @@ json2json({ foo: { bar: { baz: 1 }}}, {

`$path`, `$formatting` and nested template can work togather!
```js

@@ -160,2 +170,4 @@ json2json({ foo: { bar: { baz: 1 }}}, {

With `$disable` keyword, we can disable a field when `$disable` returns true.
```js

@@ -183,2 +195,4 @@ json2json({ foo: { bar: { baz: 1 }}}, {

When we reaches the very bottom, it possible to use `$root` to go back to the root of input json.
```js

@@ -209,2 +223,4 @@ json2json({ foo: { bar: { baz: 1 }}}, {

Map an array is so easy.
```js

@@ -211,0 +227,0 @@ json2json({

import Json2json, { Template, IJson2jsonOptions } from './Json2json';
export default function json2json<T>(json: any, template: Template<T>, options: IJson2jsonOptions) {
export default function json2json<T>(json: any, template: Template<T>, options: IJson2jsonOptions = {}) {
const mapper = new Json2json(template, options);

@@ -5,0 +5,0 @@ return mapper.map(json);

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc