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

json-linker

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-linker

Links and unlinks for json api

  • 1.5.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
174
decreased by-35.79%
Maintainers
1
Weekly downloads
 
Created
Source

json-linker

Provides linking compatible with jsonapi.

Usage Example

Linking for json serialization
// currently works only with singular models
var song = {
  title: 'Sunshine of Your Love'
  riffs: [
    { id: 'abc123', start: '1:04', stop: '1:20' },
    { id: 'qwe234', start: '2:34', stop: '2:59' }
  ],
  tags: [
    { id: 'w00t', name: 'creamy' },
    { id: '4r33l', name: 'awesome' }
  ]
}

var JsonLinker = require('json-linker')

var json = new JsonLinker(song, 'songs')
  .links('riffs', 'tags')
  .toJson()

// outputs =>
//
// {
//   songs: [{
//     title: 'Sunshine of Your Love',
//     links: {
//       riffs: ['abc123', 'qwe234'],
//       tags: ['w00t', '4r33l']
//     }
//   }],
//   linked: {
//     riffs: [
//       { id: 'abc123', start: '1:04', stop: '1:20' },
//       { id: 'qwe234', start: '2:34', stop: '2:59' }
//     ],
//     tags: [
//       { id: 'w00t', name: 'creamy' },
//       { id: '4r33l', name: 'awesome' }
//     ]
//   }
// }
Unlinking for embedded models
// currently works only with singular models
var json = {
  songs: [{
    title: 'Sunshine of Your Love',
    links: {
      riffs: ['abc123', 'qwe234'],
      tags: ['w00t', '4r33l']
    }
  }],
  linked: {
    riffs: [
      { id: 'abc123', start: '1:04', stop: '1:20' },
      { id: 'qwe234', start: '2:34', stop: '2:59' }
    ],
    tags: [
      { id: 'w00t', name: 'creamy' },
      { id: '4r33l', name: 'awesome' }
    ]
  }
}

var JsonLinker = require('json-linker')

var model = new JsonLinker(song)
  .toEmbeddedModel()
  
// outputs =>
// var song = {
//   title: 'Sunshine of Your Love'
//   riffs: [
//     { id: 'abc123', start: '1:04', stop: '1:20' },
//     { id: 'qwe234', start: '2:34', stop: '2:59' }
//   ],
//   tags: [
//     { id: 'w00t', name: 'creamy' },
//     { id: '4r33l', name: 'awesome' }
//   ]
// }

Keywords

FAQs

Package last updated on 03 Sep 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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