New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

sarala-json-api-data-formatter

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sarala-json-api-data-formatter

Simple and fluent framework agnostic javascript library to transform standard JSON API responses to simple JSON objects and vice versa.

  • 0.0.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
241
decreased by-23.49%
Maintainers
1
Weekly downloads
 
Created
Source

sarala-json-api-data-formatter

Simple and fluent framework agnostic javascript library to transform standard JSON API responses to simple JSON objects and vice versa.

Install

$ npm i sarala-json-api-data-formatter --save
$ yarn add sarala-json-api-data-formatter

JSON-API response data

const data = {
   "data": [
     {
       "type": "posts",
       "id": "1",
       "attributes": {
         "slug": "sarala-json-api-data-formatter",
         "title": "Sarala json-api data formatter",
         "subtitle": "Simple and fluent framework agnostic javascript library to transform standard JSON API responses to simple JSON objects and vice versa.",
         "published_at": "2018-01-21"
       },
       "relationships": {
         "tags": {
           "data": [
             {
               "type": "tags",
               "id": "1"
             },
             {
               "type": "tags",
               "id": "2"
             }
           ]
         }
       }
     }
   ],
   "included": [
     {
       "type": "tags",
       "id": "1",
       "attributes": {
         "name": "json-api"
       }
     },
     {
       "type": "tags",
       "id": "2",
       "attributes": {
         "name": "transform"
       }
     }
   ]
 };

Simple object data

const simpleObject = [
  {
    "id": "1",
    "type": "posts",
    "slug": "sarala-json-api-data-formatter",
    "title": "Sarala json-api data formatter",
    "subtitle": "Simple and fluent framework agnostic javascript library to transform standard JSON API responses to simple JSON objects and vice versa.",
    "published_at": "2018-01-21",
    "relationships": [
      "tags"
    ],
    "tags": [
      {
        "id": "1",
        "type": "tags",
        "name": "json-api"
      },
      {
        "id": "2",
        "type": "tags",
        "name": "transform"
      }
    ]
  }
];

Deserialize

const formatter = new Formatter();

let data = this.deserialize(data);

Serialize

const formatter = new Formatter();

let data = this.deserialize(data);

Filter relationships

deserialize only root objects and skipp all relationships
let data = this.includeOnly([]).deserialize(data);
deserialize only specific relationships

when post has tags and comments, following will deserialize only root object and comments. tags will be skipped.

let data = this.includeOnly(['comments']).deserialize(data);

Filter fields

deserialize only specified fields
let data = this.filterFields({
    posts: ['title', 'subtitle'],
    tag: ['name']
}).deserialize(data);
In the same way you can use includeOnly and filterFields with serialize method.

Keywords

FAQs

Package last updated on 09 Feb 2018

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