Skip to content

fboechats/json-object-keys

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

46 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

json-object-keys

json-object-keys | ⚠️ WIP ⚠️

Manage complex object keys in depth.

Table of contents

Install

npm install json-object-keys

Quickstart

Remove an unique key

import { remove } from 'json-object-keys'

remove(
  {
    id: 'e059d01a-7082-4b63-9c70-997491cdcf7c',
    name: 'John Doe',
    category: '65bf5579-710d-4f56-9907-8c0bb1b2f0d2',
    email: '[email protected]',
    age: 29
  },
  'category'
)

Output

+{
+  id: 'e059d01a-7082-4b63-9c70-997491cdcf7c',
+  name: 'John Doe',
-  category: '65bf5579-710d-4f56-9907-8c0bb1b2f0d2',
+  email: '[email protected]',
+  age: 29
+}
import { remove } from 'json-object-keys'

remove(
  {
    id: 'e059d01a-7082-4b63-9c70-997491cdcf7c',
    name: 'John Doe',
    category: '65bf5579-710d-4f56-9907-8c0bb1b2f0d2',
    email: '[email protected]',
    age: 29,
    node: [
      {
        id: 'e059d01a-7082-4b63-9c70-997491cdcf7c',
        name: 'John Doe',
        category: '65bf5579-710d-4f56-9907-8c0bb1b2f0d2',
        email: '[email protected]',
        age: 29,
        node: {
          id: 'e059d01a-7082-4b63-9c70-997491cdcf7c',
          name: 'John Doe',
          category: '65bf5579-710d-4f56-9907-8c0bb1b2f0d2',
          email: '[email protected]',
          age: 29,
          node: {
            id: 'e059d01a-7082-4b63-9c70-997491cdcf7c',
            name: 'John Doe',
            category: '65bf5579-710d-4f56-9907-8c0bb1b2f0d2',
            email: '[email protected]',
            age: 29
          }
        }
      },
      {
        id: 'e059d01a-7082-4b63-9c70-997491cdcf7c',
        name: 'John Doe',
        category: '65bf5579-710d-4f56-9907-8c0bb1b2f0d2',
        email: '[email protected]',
        age: 29,
        node: {
          id: 'e059d01a-7082-4b63-9c70-997491cdcf7c',
          name: 'John Doe',
          category: '65bf5579-710d-4f56-9907-8c0bb1b2f0d2',
          email: '[email protected]',
          age: 29
        }
      },
      {
        id: 'e059d01a-7082-4b63-9c70-997491cdcf7c',
        name: 'John Doe',
        category: '65bf5579-710d-4f56-9907-8c0bb1b2f0d2',
        email: '[email protected]',
        age: 29,
        node: {
          id: 'e059d01a-7082-4b63-9c70-997491cdcf7c',
          name: 'John Doe',
          category: '65bf5579-710d-4f56-9907-8c0bb1b2f0d2',
          email: '[email protected]',
          age: 29,
          node: {
            id: 'e059d01a-7082-4b63-9c70-997491cdcf7c',
            name: 'John Doe',
            category: '65bf5579-710d-4f56-9907-8c0bb1b2f0d2',
            email: '[email protected]',
            age: 29
          }
        }
      }
    ]
  },
  'id'
)

Output

+{
-  id: 'e059d01a-7082-4b63-9c70-997491cdcf7c',
+  name: 'John Doe',
+  category: '65bf5579-710d-4f56-9907-8c0bb1b2f0d2',
+  email: '[email protected]',
+  age: 29,
+  node: [
+    {
-      id: 'e059d01a-7082-4b63-9c70-997491cdcf7c',
+      name: 'John Doe',
+      category: '65bf5579-710d-4f56-9907-8c0bb1b2f0d2',
+      email: '[email protected]',
+      age: 29,
+      node: {
-        id: 'e059d01a-7082-4b63-9c70-997491cdcf7c',
+        name: 'John Doe',
+        category: '65bf5579-710d-4f56-9907-8c0bb1b2f0d2',
+        email: '[email protected]',
+        age: 29,
+        node: {
-          id: 'e059d01a-7082-4b63-9c70-997491cdcf7c',
+          name: 'John Doe',
+          category: '65bf5579-710d-4f56-9907-8c0bb1b2f0d2',
+          email: '[email protected]',
+          age: 29
+        }
+      }
+    },
+    {
-      id: 'e059d01a-7082-4b63-9c70-997491cdcf7c',
+      name: 'John Doe',
+      category: '65bf5579-710d-4f56-9907-8c0bb1b2f0d2',
+      email: '[email protected]',
+      age: 29,
+      node: {
-        id: 'e059d01a-7082-4b63-9c70-997491cdcf7c',
+        name: 'John Doe',
+        category: '65bf5579-710d-4f56-9907-8c0bb1b2f0d2',
+        email: '[email protected]',
+        age: 29
+      }
+    },
+    {
-      id: 'e059d01a-7082-4b63-9c70-997491cdcf7c',
+      name: 'John Doe',
+      category: '65bf5579-710d-4f56-9907-8c0bb1b2f0d2',
+      email: '[email protected]',
+      age: 29,
+      node: {
-        id: 'e059d01a-7082-4b63-9c70-997491cdcf7c',
+        name: 'John Doe',
+        category: '65bf5579-710d-4f56-9907-8c0bb1b2f0d2',
+        email: '[email protected]',
+        age: 29,
+        node: {
-          id: 'e059d01a-7082-4b63-9c70-997491cdcf7c',
+          name: 'John Doe',
+          category: '65bf5579-710d-4f56-9907-8c0bb1b2f0d2',
+          email: '[email protected]',
+          age: 29
+        }
+      }
+    }
+  ]
+}

Remove multiple keys

import { remove } from 'json-object-keys'

remove(
  {
    id: 'e059d01a-7082-4b63-9c70-997491cdcf7c',
    name: 'John Doe',
    category: '65bf5579-710d-4f56-9907-8c0bb1b2f0d2',
    email: '[email protected]',
    age: 29
  },
  ['category', 'email']
)

Output

+{
+  id: 'e059d01a-7082-4b63-9c70-997491cdcf7c',
+  name: 'John Doe',
-  category: '65bf5579-710d-4f56-9907-8c0bb1b2f0d2',
-  email: '[email protected]',
+  age: 29
+}
import { remove } from 'json-object-keys'

remove(
  {
    id: 'e059d01a-7082-4b63-9c70-997491cdcf7c',
    name: 'John Doe',
    category: '65bf5579-710d-4f56-9907-8c0bb1b2f0d2',
    email: '[email protected]',
    age: 29,
    node: [
      {
        id: 'e059d01a-7082-4b63-9c70-997491cdcf7c',
        name: 'John Doe',
        category: '65bf5579-710d-4f56-9907-8c0bb1b2f0d2',
        email: '[email protected]',
        age: 29,
        node: {
          id: 'e059d01a-7082-4b63-9c70-997491cdcf7c',
          name: 'John Doe',
          category: '65bf5579-710d-4f56-9907-8c0bb1b2f0d2',
          email: '[email protected]',
          age: 29,
          node: {
            id: 'e059d01a-7082-4b63-9c70-997491cdcf7c',
            name: 'John Doe',
            category: '65bf5579-710d-4f56-9907-8c0bb1b2f0d2',
            email: '[email protected]',
            age: 29
          }
        }
      },
      {
        id: 'e059d01a-7082-4b63-9c70-997491cdcf7c',
        name: 'John Doe',
        category: '65bf5579-710d-4f56-9907-8c0bb1b2f0d2',
        email: '[email protected]',
        age: 29,
        node: {
          id: 'e059d01a-7082-4b63-9c70-997491cdcf7c',
          name: 'John Doe',
          category: '65bf5579-710d-4f56-9907-8c0bb1b2f0d2',
          email: '[email protected]',
          age: 29
        }
      },
      {
        id: 'e059d01a-7082-4b63-9c70-997491cdcf7c',
        name: 'John Doe',
        category: '65bf5579-710d-4f56-9907-8c0bb1b2f0d2',
        email: '[email protected]',
        age: 29,
        node: {
          id: 'e059d01a-7082-4b63-9c70-997491cdcf7c',
          name: 'John Doe',
          category: '65bf5579-710d-4f56-9907-8c0bb1b2f0d2',
          email: '[email protected]',
          age: 29,
          node: {
            id: 'e059d01a-7082-4b63-9c70-997491cdcf7c',
            name: 'John Doe',
            category: '65bf5579-710d-4f56-9907-8c0bb1b2f0d2',
            email: '[email protected]',
            age: 29
          }
        }
      }
    ]
  },
  ['email', 'category', 'age']
)

Output

+{
+  id: 'e059d01a-7082-4b63-9c70-997491cdcf7c',
+  name: 'John Doe',
-  category: '65bf5579-710d-4f56-9907-8c0bb1b2f0d2',
-  email: '[email protected]',
-  age: 29,
+  node: [
+    {
+      id: 'e059d01a-7082-4b63-9c70-997491cdcf7c',
+      name: 'John Doe',
-      category: '65bf5579-710d-4f56-9907-8c0bb1b2f0d2',
-      email: '[email protected]',
-      age: 29,
+      node: {
+        id: 'e059d01a-7082-4b63-9c70-997491cdcf7c',
+        name: 'John Doe',
-        category: '65bf5579-710d-4f56-9907-8c0bb1b2f0d2',
-        email: '[email protected]',
-        age: 29,
+        node: {
+          id: 'e059d01a-7082-4b63-9c70-997491cdcf7c',
+          name: 'John Doe',
-          category: '65bf5579-710d-4f56-9907-8c0bb1b2f0d2',
-          email: '[email protected]',
-          age: 29
+        }
+      }
+    },
+    {
+      id: 'e059d01a-7082-4b63-9c70-997491cdcf7c',
+      name: 'John Doe',
-      category: '65bf5579-710d-4f56-9907-8c0bb1b2f0d2',
-      email: '[email protected]',
-      age: 29,
+      node: {
+        id: 'e059d01a-7082-4b63-9c70-997491cdcf7c',
+        name: 'John Doe',
-        category: '65bf5579-710d-4f56-9907-8c0bb1b2f0d2',
-        email: '[email protected]',
-        age: 29
+      }
+    },
+    {
+      id: 'e059d01a-7082-4b63-9c70-997491cdcf7c',
+      name: 'John Doe',
-      category: '65bf5579-710d-4f56-9907-8c0bb1b2f0d2',
-      email: '[email protected]',
-      age: 29,
+      node: {
+        id: 'e059d01a-7082-4b63-9c70-997491cdcf7c',
+        name: 'John Doe',
-        category: '65bf5579-710d-4f56-9907-8c0bb1b2f0d2',
-        email: '[email protected]',
-        age: 29,
+        node: {
+          id: 'e059d01a-7082-4b63-9c70-997491cdcf7c',
+          name: 'John Doe',
-          category: '65bf5579-710d-4f56-9907-8c0bb1b2f0d2',
-          email: '[email protected]',
-          age: 29
+        }
+      }
+    }
+  ]
+}

License

This project is licensed under the MIT License.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 100.0%