npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

jsonlt

v0.1.1

Published

JSON Lazy Transformation

Downloads

2

Readme

JSONLT

JSON Lazy Transformation

Surprisingly I didn't find anything that can help me to solve the trivial problem - transform one simple JSON object to another without writing any code.

For example we have this object...

{
	"firstName": "John",
	"lastName": "Smith",
	"address": {
		"suburb": "Brisbane",
		"street": "200 Adelaide street"
	}
}

... that we can transform to ...

{
	"name": "John Smith",
	"address": "Brisbane,200 Adelaide street"
}

... using rule object:

{
	"name": "#firstName #lastName",
	"address": "#address^"
}

Install

You can use JSONLT in your io.js / Node.js application and then you probably would like to install it using npm:

npm install jsonlt --save

Or you can use it in your client side application and then bower is a good choice:

bower install jsonlt --save

Usage

In io.js / Node.js project var JSONLT = require('jsonlt');

Or in browser add <script src="/path/to/jsonlt.min.js"></script> and it will register global variable JSONLT

And then:

var foo = new JSONLT();
foo.transform(sourceObject, rulesObject);

You can pass options object to constructor new JSONLT(options). JSONLT supports these options so far:

strict : boolean

JSONLT will abort transformation if there is an error and strict option set to true. Otherwise it will return an empty string for failed transformation. It set to false by default.

Transformation object syntax:

@jsonlt

Version of JSONLT, if not specified - the latest

#fieldName

Return field from the input JSON object

#fieldName.propertyName

Return object.propertyName

#fieldName[index]

Return value from array by index, -1 = last item

#(type)fieldName

Cast to type

#fieldName|propertyName=value

Return array Array.filter by propertyName = value

#fieldName*propertyName

Return array of fieldName.propertyName elements

#fieldName^delimeter

Return string with object values divided by delimeters

Browsers support

Normal browsers and IE9+

More examples

We have simple JSON input:

{
	"firstName": "John",
	"lastName": "Smith",
	"address": {
		"suburb": "Brisbane",
		"postCode": 4000,
		"street": "200 Adelaide"
	},
	"orders": [ 2342000, 2342001, 23400015],
	"items": [
		{
			"type": "book",
			"description": "Simple book..."
		},
		{
			"type": "CD",
			"description": "Simple music CD",
			"artist": "Unknown Artist"
		}
	]
}

... and then we're applying the JSONLT template ...

{
	"@jsonlt": 1,
	"person": {
		"firstName": "#firstName",
		"lastName": "#lastName"
	},
	"lastOrder": "#orders[-1]",
	"ordersString": "#(string)orders",
	"CDs": "#items|type='CD'",
	"descriptions": "#items*description",
	"address": "#address^,",
	"addressNormal": "#address.street, #address.suburb #address.postCode",
	"totalOrders": "#orders.length"
}

.. to have this JSON output

{
	"person": {
		"firstName": "John",
		"lastName": "Smith"
	},
	"lastOrder": 23400015,
	"lastOrderString": "2342000,2342001,23400015",
	"CDs": [
		{
			"type": "CD",
			"description": "Simple music CD",
			"artist": "Unknown Artist"
		}
	],
	"descriptions": ["Simple book...", "Simple music CD"],
	"address": "Brisbane, 4000, 200 Adelaide",
	"addressNormal": "200 Adelaide, Brisbane 4000",
	"totalOrders": 3
}

##Contributing

####Install project dependencies

  npm install

####Grunt Tasks grunt build Runs test and creates /dist folder including minified version

grunt test Runs unit tests

License

The MIT License (MIT)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.