Gathering detailed insights and metrics for pinkie-json-serializer
Gathering detailed insights and metrics for pinkie-json-serializer
Gathering detailed insights and metrics for pinkie-json-serializer
Gathering detailed insights and metrics for pinkie-json-serializer
Little library for JSON serializing. Easily applicable as database plugin, which limits outputted data.
npm install pinkie-json-serializer
Typescript
Module System
Node Version
NPM Version
72
Supply Chain
98.4
Quality
75
Maintenance
100
Vulnerability
100
License
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
2 Stars
10 Commits
1 Watchers
1 Branches
1 Contributors
Updated on Mar 19, 2019
Latest Version
1.0.2
Package Id
pinkie-json-serializer@1.0.2
Size
4.61 kB
NPM Version
2.15.0
Node Version
4.4.2
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
A simple, lightweight JSON serializer. I was inspired by active-model-serializer for Ruby, but this one is not binded to one specific technology(ActiveModel ORM for example) and can be easily implemented in any situation.
Pinkie is available on npm.
npm install --save pinkie-json-serializer
Let's say we fetch data from our database in this form:
1var user = { 2 "id" : 3, 3 "username" : "Mrs.Sparkle", 4 "password" : "un4re8da0bl34ash", 5 "gender" : "F", 6 "last_login" : 14712041 7}
It would be nice to have one place in our project, where we could properly format our output. So we hook up this serializer in our data access layer. It may look as follows:
1 var Serializer = require('pinkie-serializer'); 2 var serializer = new Serializer(); 3 4 function isOwner(id){ 5 return (id === 4); 6 } 7 8 var serialization_schema = { 9 "name" : {"as" : "username"}, 10 "gender" : true, 11 "password" : { 12 "show" : function(json){ 13 return isOwner(json["id"]); 14 } 15 }, 16 "last_login" : { 17 "set" : function(json){ 18 return { 19 "utc" : json["last_login"], //our fetched time 20 "halved" : json["last_login"]/2 21 } 22 }; 23 } 24 }; 25 var user = fetch_by_id(3); //pseudo-function 26 var serialized = serializer.serialize(user, schema); 27 console.log(serialized); 28 29 //Outputs 30 { 31 "username" : "Mrs.Sparkle", 32 "gender" : "F", 33 "last_login" : { 34 "utc" : 14712041, 35 "halved" : 7356020.5 36 } 37 }
Schema allows nested arrays and objects, but in this case the "show" value must contain next serialization schema.
I used it as a Moongose plugin when I was building my API. I implemented it as Moongose middleware, but it has some downsides like inability to access request object and parse headers for example(in this case you may want to create serialize method on your model with request arg).
1 //src/models/plugins/serializer.js 2 var Serializer = require('pinkie-serializer'); 3 var serializer = new Serializer(); 4 5 module.exports = function(schema, serialization_schema){ 6 schema.methods.toJSON = function(){ 7 return serializer.serialize(this.toObject(), serialization_schema, this); 8 }; 9 };
1 //src/models/user.js 2 var mongoose = require('mongoose'); 3 var serializer = require('./plugins/serializer'); 4 5 6var userSchema = new mongoose.Schema({ 7 name: { 8 type: String 9 }, 10 gender:{ 11 type: String, 12 enum: ["M", "F"] 13 }, 14 password:{ 15 type: String 16 } 17 last_login:{ 18 type: Number 19 } 20}); 21 22userSchema.plugin(serializer, { 23 "_id" : {"as" : "id"}, 24 "name" : {"as" : "username"}, 25 "gender" : { 26 "set" : function(json, user){ 27 //user is moongose object we passed in serializer.js as a 3rd param. we can use it to access related objects if we need any 28 29 if(json["gender"] === "F"){ 30 return "girl"; 31 }else{ 32 return "boy"; 33 } 34 } 35 } 36}); 37 38module.exports = mongoose.model('User', userSchema);
Now if you query your DB via you'll be responded with nicely formatted output.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
Found 0/10 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
license file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Score
Last Scanned on 2025-07-14
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More