All Projects → gagan-bansal → json-groupby

gagan-bansal / json-groupby

Licence: MIT License
Group json data based on properties of json

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to json-groupby

Unix Permissions
Swiss Army knife for Unix permissions
Stars: ✭ 106 (+523.53%)
Mutual labels:  group
discord-group-spammer
You need to run all_together.py and follow the instructions on the readme below. This Tool allows you to use various discord exploits for educational use.
Stars: ✭ 45 (+164.71%)
Mutual labels:  group
clubi
A group-oriented social media platform written in Laravel and Vue
Stars: ✭ 29 (+70.59%)
Mutual labels:  group
Simplerecyclerview
Android RecyclerView 简化使用: 下拉刷新, 加载更多, 加载中/空数据/错误页面, 固定Header, 分割线, 点击监听, Item 动画, 分组显示 Title. (Android RecyclerView easy-to-use: Pull-To-Refresh, load more, Loading/Empty/Error View, sticky headers, divider, click listener, item animation, group display.)
Stars: ✭ 134 (+688.24%)
Mutual labels:  group
Publicleech
can be found on Telegram as https://telegram.dog/PublicLeechGroup
Stars: ✭ 236 (+1288.24%)
Mutual labels:  group
EnterpriseALRobot
An anime themed telegram group management bot
Stars: ✭ 134 (+688.24%)
Mutual labels:  group
Aws Securitygroup Grapher
This ansible role gets information from an AWS VPC and generate a graphical representation of security groups
Stars: ✭ 93 (+447.06%)
Mutual labels:  group
PyroGramBot
pluggable Telegram Bot based on Pyrogram
Stars: ✭ 168 (+888.24%)
Mutual labels:  group
flutter sticky and expandable list
粘性头部与分组列表Sliver实现 Build a grouped list, which support expand/collapse section and sticky headers, support use it with sliver widget.
Stars: ✭ 116 (+582.35%)
Mutual labels:  group
WarezBot
Public Version of Discord bot for scene release
Stars: ✭ 30 (+76.47%)
Mutual labels:  group
Gitlabber
Gitlabber - clones or pulls entire groups tree from gitlab
Stars: ✭ 176 (+935.29%)
Mutual labels:  group
Tms
基于频道模式的团队沟通协作+轻量级任务看板,支持mardown、富文本、在线表格和思维导图的团队博文wiki,i18n国际化翻译管理的响应式web开源团队协作系统。
Stars: ✭ 232 (+1264.71%)
Mutual labels:  group
zusam
Private groups to share messages, photos, videos, links with friends and family.
Stars: ✭ 79 (+364.71%)
Mutual labels:  group
Arithmoi
Number theory: primes, arithmetic functions, modular computations, special sequences
Stars: ✭ 117 (+588.24%)
Mutual labels:  group
img-master
An image batch processing tool with multifunctional and unlimited
Stars: ✭ 63 (+270.59%)
Mutual labels:  group
Wheel
Quick navigation framework for Vim and Neovim : buffer groups, mru, locate, find, grep, outline, yank, ...
Stars: ✭ 94 (+452.94%)
Mutual labels:  group
SophiaBot
Hi There ✋ I'M Sophia 3.0 ❤️ NEW VERSION OF SOPHIA.. Source Code of @SophiaSLBot.
Stars: ✭ 44 (+158.82%)
Mutual labels:  group
libnss-aad
A glibc NSS plugin that implements an Azure Active Directory service
Stars: ✭ 17 (+0%)
Mutual labels:  group
brackets-viewer.js
A simple library to display tournament brackets (round-robin, single elimination, double elimination).
Stars: ✭ 52 (+205.88%)
Mutual labels:  group
datar
A Grammar of Data Manipulation in python
Stars: ✭ 142 (+735.29%)
Mutual labels:  groupby

json-groupby

Group array of JSON objects based on associated properties.

It also groups objects containing nested arrays.

installation

npm install json-groupby

usage

var groupBy = require('json-groupby')
var group = groupBy(array, properties [, collect])
  • array Array of JSON objects

  • properties Array JSON properties' path like address.city or lookup object

    lookup

    {
      intervals: array of numbers
      ,property: string
      [,labels: array of string]
    }
    

    intervals Array of intervals. Like [ 10, 20, 30, 40, 50] group the data in four ranges, whereas lower bound is inclusive and upper bound is exclusive.

    peroperty Property path like price

    labels Array of interval labels like [ 'low', 'medium', 'high']

  • collect Array of properties that need to be collected in array

examples

data set

var products = 
 [{"id": 1,
   "product": "ri", "price": 16, "color": "green", "available": false,
   "tags": ["bravo"],
   "vendor": {"name": "Donald Chambers", "address": {"city": "Mumbai"}}},
  {"id": 2,
   "product": "foef", "price": 44, "color": "yellow", "available": false,
   "tags": ["alpha"],
   "vendor": {"name": "Barbara Garrett", "address": {"city": "Mumbai"}}},
  {"id": 3,
   "product": "jehnojto", "price": 29, "color": "red", "available": true,
   "tags": ["alpha"],
   "vendor": {"name": "Anne Leonard", "address": {"city": "New York"}}},
  {"id": 4,
   "product": "ru", "price": 35, "color": "yellow", "available": false,
   "tags": ["echo", "charlie", "bravo"],
   "vendor": {"name": "Justin Doyle", "address": {"city": "London"}}},
  {"id": 5,
   "product": "pihluve", "price": 47, "color": "green", "available": true,
   "tags": ["delta", "echo", "bravo"],
   "vendor": {"name": "Emily Abbott", "address": {"city": "New York"}}},
  {"id": 6,
   "product": "dum", "price": 28, "color": "green", "available": true,
   "tags": ["echo", "delta", "charlie"],
   "vendor": {"name": "Henry Peterson", "address": {"city": "New York"}}},
  {"id": 7,
   "product": "zifpeza", "price": 10, "color": "green", "available": false,
   "tags": ["echo", "charlie", "bravo"],
   "vendor": {"name": "Jesus Lowe", "address": {"city": "Mumbai"}}},
  {"id": 8,
   "product": "av", "price": 39, "color": "green", "available": true,
   "tags": ["bravo"],
   "vendor": {"name": "Rosalie Erickson", "address": {"city": "New York"}}}]

group by single property

groupBy(products, ['color'], ['id'])
// output is 
{ green: { id: [ 1, 5, 6, 7, 8 ] },
  yellow: { id: [ 2, 4 ] },
  red: { id: [ 3 ] } }

group by many properties and without collect option

groupBy(products, ['available', 'color', 'vendor.address.city'])
// output is 
{"false": 
  {"green": 
    {"Mumbai": [
      {"id": 1, "product": "ri", "price": 16, "color": "green", 
       "available": false, "tags": ["bravo"], 
       "vendor": {"name": "Donald Chambers",  "address": {"city": "Mumbai"}}},
      {"id": 7, "product": "zifpeza", "price": 10, "color": "green",
       "available": false, "tags": ["echo", "charlie", "bravo"],
       "vendor": {"name": "Jesus Lowe", "address": {"city": "Mumbai"}}}]},
   "yellow": {
     "Mumbai": [
       {"id": 2, "product": "foef", "price": 44, "color": "yellow", 
        "available": false, "tags": ["alpha"], 
        "vendor": {"name": "Barbara Garrett",  "address": {"city": "Mumbai"}}}], 
     "London": [
       {"id": 4, "product": "ru", "price": 35, "color": "yellow",
        "available": false, "tags": ["echo", "charlie", "bravo"],
        "vendor": {"name": "Justin Doyle", "address": {"city": "London"}}}]}},
 "true": 
  {"red": 
    {"New York": [
      {
        "id": 3, "product": "jehnojto", "price": 29, "color": "red",
        "available": true, "tags": ["alpha"],
        "vendor": {"name": "Anne Leonard", "address": {"city": "New York"}}}]},
   "green": {
     "New York": [
        {"id": 5, "product": "pihluve", "price": 47, "color": "green",
         "available": true, "tags": ["delta", "echo", "bravo"],
         "vendor": {"name": "Emily Abbott", "address": {"city": "New York"}}},
         {"id": 6, "product": "dum", "price": 28, "color": "green",
         "available": true, "tags": ["echo", "delta", "charlie"],
         "vendor": {"name": "Henry Peterson", "address": {"city": "New York"}}},
         {"id": 8, "product": "av", "price": 39, "color": "green",
         "available": true, "tags": ["bravo"],
         "vendor": {"name": "Rosalie Erickson", "address": {"city": "New York"}}}
     ]}}}

single deep path property

groupBy(products, ['vendor.address.city'], ['id'])
// output is 
{ Mumbai: { id: [ 1, 2, 7 ] },
  'New York': { id: [ 3, 5, 6, 8 ] },
  London: { id: [ 4 ] } }

group with boolean property

groupBy(products, ['available'], ['id'])
// output is 
{ false: { id: [ 1, 2, 4, 7 ] }, 
  true: { id: [ 3, 5, 6, 8 ] }}

group by intervals (lookup of intervals) without intervals' name

groupBy(
  products, 
  [{property: 'price', intervals: [10,20,40,50]}],
  ['id'])
//output is 
{ '0': { id: [ 1, 7 ] },
  '1': { id: [ 3, 4, 6, 8 ] },
  '2': { id: [ 2, 5 ] } }

group by intervals (lookup of intervals) with intervals' lable name

groupBy(
  products, 
  [{
    property: 'price', 
    intervals: [10,20,40,50], 
    labels: ['low','medium','high']}],
  ['id'])
//ouptu is 
{'low': { id: [ 1, 7 ] },
 'medium': { id: [ 3, 4, 6, 8 ] },
 'high': { id: [ 2, 5 ] } }

group with mixed properties lookup and property path

groupBy(
  products, 
  [
    {
      property: 'price', 
      intervals: [10,20,40,50], 
      labels: ['low','medium','high']
    },
    'vendor.address.city'
  ],
  ['id'])
// output is
{
  "low":
    {"Mumbai":{"id":[1,7]}},
  "high":
    {"Mumbai":{"id":[2]},
    "New York":{"id":[5]}},
  "medium":
    {"New York":{"id":[3,6,8]},
    "London":{"id":[4]}}

group by tags that are in array

groupBy(products, ['tags'], ['id'])
//ouput is
{ bravo: { id: [ 1, 4, 5, 7, 8 ] },
  alpha: { id: [ 2, 3 ] },
  echo: { id: [ 4, 5, 6, 7 ] },
  charlie: { id: [ 4, 6, 7 ] },
  delta: { id: [ 5, 6 ] } }

group and collect many properties

groupBy(
  products, 
  ['color'], 
  ['vendor.address.city', 'available'])
// output is
{ green: 
   { 'vendor.address.city': [ 'Mumbai', 'New York', 'New York', 'Mumbai', 'New York' ],
     available: [ false, true, true, false, true ] },
  yellow: 
   { 'vendor.address.city': [ 'Mumbai', 'London' ],
     available: [ false, false ] },
  red: { 'vendor.address.city': [ 'New York' ], available: [ true ] } }

Nested Arrays

Group by property path that lies in nested arrays, in the following example addresses.localities.size

var vendors = [{
  id: 1,
  addresses : [{
    city: 'a',
    localities: [
      {size: "small", zipcode: '12345', storeType: ['electronic', 'food']},
      {size: "medium", zipcode: '12346', storeType: ['food']}]
  }, {
    city: 'b',
    localities: [
      {size: "medium", zipcode: '12345', storeType: ['electronic', 'food']},
      {size: "small", zipcode: '12347', storeType: ['electronic']}]
  }],
  details: {
    name: 'foo', 
    items: 400, 
    rating: 'high'}
}, {
  id: 2,
  addresses : [{
    city: 'a',
    localities: [
      {size: "large", zipcode: '12345', storeType: ['apparel', 'furniture']},
      {size: "small", zipcode: '12346', storeType: ['furniture']}]
  }, {
    city: 'b',
    localities: [
      {size: "small", zipcode: '12345', storeType: ['food', 'furniture']},
      {size: "medium", zipcode: '12347', storeType: ['food']}]
  }],
  details: {
    name: 'bar', 
    items: 500, 
    rating: 'low'}
}]

var group = groupBy(vendors, ['addresses.localities.size'], ['id'])

// output gruop is
{
  "small": {id: [1, 2]},
  "medium": {id: [1, 2]},
  "large": {id: [2]}
}

developing

Once you run

npm isntall

then for running test

npm run test

to create build

npm run build

license

This project is licensed under the terms of the MIT license.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].