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

@sedeh/extensible-json-transformations

v3.0.1

Published

Have you ever wanted to perform query on a JSON? Have you ever wanted to consume it in a program but the JSON was in a form not suitable for your program? Have you wanted to use the JSON without writing any code to do it? Have you wondered what it takes

Downloads

17

Readme

Welcome to Extensible JSON transformations!

Have you ever wanted to perform query on a JSON? Have you ever wanted to consume it in a program but the JSON was in a form not suitable for your program? Have you wanted to use the JSON without writing any code to do it? Have you wondered what it takes to make this happen? Well... wonder no more and add this component into your project...

NOTE: Starting with version 1.1.0 this library is compatible with Angular 6+.

NOTE: Starting with version 1.3.0 you need to import this library through @sedeh/extensible-json-transformations.

Live Demo | Comments/Requests

MODULE:
	XjsltModule
	
EXPORTS:
	XjsltComponent
	Transformations
	Template
	Styler
	JsonAsDataSource
	Inquirer

Definitions

XJSLT: Extensible JSON Styling Language Transformation
	The process in which a JSON is morphed into a different JSON to be consumed by a program.

JS: JSON Styling
	Style a JSON into a more presentable JSON for a given purpose.

JSL: JSON Styling Language
	Language that supports JSON Styling.

JST: JSON Styling Template
	Template to be used specifically for the purpose of JSON Styling.

Transformations

Styling Methods

| Method | Example | Arguments | Description | |------------|---------------------------------------------------------|-----------|------------------------------------------------------------| | valueOf | valueOf(a.b.c) | 1) JPath | Traverse the given JPath and return its value. | | enlist | enlist(valueOf(a),valueOf(b),valueOf(c)) | 1) Array | Insert argument values into a list | | split | split(valueOf(friends.namebank_ids),',') | 1) Value, 2) Delimiter | Split value into a list | | join | join(select(friends.name),',') | 1) array, 2) Delimiter | Join items of the list into a string | | concat | concat(valueOf(name),' ',valueOf(age)) | 1) Argument values | Join arguments into a string | | each | each(select(friends.address),zipCode) | 1) Array, 2) JPath | For each item in array, evaluate the JPath | | select | select(friends.address) | 1) JPath | Select the nodes with given JPath in current context | | filter | filter(id,in,valueOf(selected_ids)) | 1) JPath, 2) Operation, 3) Value to match | For value of target in current context, evaluate operation for given value(s). Supported operations are =,<,>,in,!. For list values 'in' operation means "contains" and for string value it means "indexOf". Negating operation '!' means not equal or not in. | | style | style(templateName, select(friends.address)) | 1) Template name, 2) Array | Apply the given template for the given array | | match | match(templateName,user.id,in,spit(valueOf(id_list))) | 1) Template name, 2) JPath to a target, 3) Operation, 4) Value to match | For value of target in given template nodes, evaluate and operation for given value(s) and return nodes that are matching the operation. Supported operations are =,<,>,in,!. For list values 'in' operation means "contains" and for string value it means "indexOf". Negating operation '!' means not equal or not in. | | apply | apply(trmplateName,id,split(valueOf(user_ids),'')) | 1) Template name, 2) JPath, 3) Value(s) | Apply the template name in current context for each node that matches the given path. | | offPool | offPool(template,valueOf(id)) | 1) Template name, 2) Key | Use the given template pool to pick up item(s) with given key(s) |

structures

export interface Transformations {
	name: string,
	importUrls?:string[],
	rootTemplate: string,
	onResult?: string,
	templates: Template[]
}

| Attribute | Description | |--------------|------------------------------------------------------------------------------------------| | name | Name chosen for the transformation | | importUrls | List of urls to import other transformations | | rootTemplate | The template name to start the transformation | | onResult | A method to be invoked on completion of transformations. Could be a filter to exclude some results or any other method. | | templates | List of templates |

export interface Template {
	name: string,
	match: string,
	value?: string,
	context: string,
	inPool?: string,
	style: any
}

| Attribute | Description | |-----------|---------------------------------------------------------------------------------------------| | name | Name chosen for the template | | match | Path to start the styling | | value | Value to evaluate the math. not needed if match is on root node or blank | | context | The node to be used. "root" means the root node. "current" means the node currently in play.| | inPool | Pre-process all items with given JPath as a key in a pool. Example: 'id' or 'friends.id' |

NOTE: if you get "RangeError: Maximum call stack size exceeded" message, it means an infinite loop is created because of circular referencing in multiple templates.

So... How it can be done?

Run npm install extensible-json-transformation in your application. and do the following:

If you want to use the transformation component, do the following in your html:

<xjslt
	[node]="myDataSet"
	[transformations]="transformations"
	(onerror)="takeErrorMessageFrom($event)"
	(ontransformation)="ontransformation($event)"></xjslt>

where

transformations  could  be ={
	"name": "products",
	"importUrls": [],
	"rootTemplate": ".",
	"onResult": "",
	"templates": [{
		"name":  ".",
		"match":  "",
		"context":  "root",
		"style": {
		"name":  "valueOf(name)",
		"vendor":  "valueOf(vendor.name)",
		"trackNames":  "each(select(details),name)"
		}
	}]
}

If you want to directly use the transformation object, do the following in your code:

	const styler = new Styler(theJsonForTransfromation);

	styler.changeRootNode(theJsonRootNode);
	styler.transform();

If you want to directly query a JSON object using transformation methods, do the following in your code:

	const inquirer = new Inquirer();
	const queryResponse = inquirer.query("set of nested function calls", theJsonRootNode);
	
	where nested function calls could be `enlist(valueOf(a),valueOf(b),valueOf(c))`

Version History

| Version | Description | |---------|----------------------------------------------------------------------------------------------------------| | 3.0.1 | Ubdated to angular 15 | | 2.0.0 | Updated to Angular 8. | | 1.3.1 | Updated dependencies. | | 1.3.0 | Re-organizing libraries I am providing. Added scope to the project. From now on Accessing through @sedeh/extensible-json-transformations | | 1.2.0 | It was brought to my attention that some users have trouble using my components in their angular 6 environment. Since I had only updated few dependencies when moved to Angular 6, I am thinking dependencies are causing issues. So, for this release, I am updating all dependencies to what Angular 6 applications are expecting to have. Please let me know if this is fixing or not fixing any issues you are facing. | | 1.1.0 | Updated libraries to become compatible with Angular 6+. | | 1.0.0 | Compiled with AOT option and resolved issues. | | 0.1.1 | fixed few logic errors to handle complex JSON structures. | | 0.1.0 | Added ability to query a JSON directly. fixed few logic errors. | | 0.0.1 | Initial release. |

alt text