delete operator is used to remove an object property.

delete operator does not returns the new object, only returns a boolean: true or false.

In the other hand, after interpreter executes var updatedjsonobj = delete myjsonobj['otherIndustry']; , updatedjsonobj variable will store a boolean value.

How to remove Json object specific key and its value ?

You just need to know the property name in order to delete it from the object's properties.

delete myjsonobj['otherIndustry'];

let myjsonobj = {
  "employeeid": "160915848",
  "firstName": "tet",
  "lastName": "test",
  "email": "test@email.com",
  "country": "Brasil",
  "currentIndustry": "aaaaaaaaaaaaa",
  "otherIndustry": "aaaaaaaaaaaaa",
  "currentOrganization": "test",
  "salary": "1234567"
}
delete myjsonobj['otherIndustry'];
console.log(myjsonobj);

If you want to remove a key when you know the value you can use Object.keys function which returns an array of a given object's own enumerable properties.

let value="test";
let myjsonobj = {
      "employeeid": "160915848",
      "firstName": "tet",
      "lastName": "test",
      "email": "test@email.com",
      "country": "Brasil",
      "currentIndustry": "aaaaaaaaaaaaa",
      "otherIndustry": "aaaaaaaaaaaaa",
      "currentOrganization": "test",
      "salary": "1234567"
}
Object.keys(myjsonobj).forEach(function(key){
  if (myjsonobj[key] === value) {
    delete myjsonobj[key];
  }
});
console.log(myjsonobj);

Answer from Mihai Alexandru-Ionut on Stack Overflow
Top answer
1 of 7
129

delete operator is used to remove an object property.

delete operator does not returns the new object, only returns a boolean: true or false.

In the other hand, after interpreter executes var updatedjsonobj = delete myjsonobj['otherIndustry']; , updatedjsonobj variable will store a boolean value.

How to remove Json object specific key and its value ?

You just need to know the property name in order to delete it from the object's properties.

delete myjsonobj['otherIndustry'];

let myjsonobj = {
  "employeeid": "160915848",
  "firstName": "tet",
  "lastName": "test",
  "email": "test@email.com",
  "country": "Brasil",
  "currentIndustry": "aaaaaaaaaaaaa",
  "otherIndustry": "aaaaaaaaaaaaa",
  "currentOrganization": "test",
  "salary": "1234567"
}
delete myjsonobj['otherIndustry'];
console.log(myjsonobj);

If you want to remove a key when you know the value you can use Object.keys function which returns an array of a given object's own enumerable properties.

let value="test";
let myjsonobj = {
      "employeeid": "160915848",
      "firstName": "tet",
      "lastName": "test",
      "email": "test@email.com",
      "country": "Brasil",
      "currentIndustry": "aaaaaaaaaaaaa",
      "otherIndustry": "aaaaaaaaaaaaa",
      "currentOrganization": "test",
      "salary": "1234567"
}
Object.keys(myjsonobj).forEach(function(key){
  if (myjsonobj[key] === value) {
    delete myjsonobj[key];
  }
});
console.log(myjsonobj);

2 of 7
22

There are several ways to do this, lets see them one by one:

  1. delete method: The most common way

const myObject = {
    "employeeid": "160915848",
    "firstName": "tet",
    "lastName": "test",
    "email": "test@email.com",
    "country": "Brasil",
    "currentIndustry": "aaaaaaaaaaaaa",
    "otherIndustry": "aaaaaaaaaaaaa",
    "currentOrganization": "test",
    "salary": "1234567"
};

delete myObject['currentIndustry'];
// OR delete myObject.currentIndustry;
  
console.log(myObject);

  1. By making key value undefined: Alternate & a faster way:

let myObject = {
    "employeeid": "160915848",
    "firstName": "tet",
    "lastName": "test",
    "email": "test@email.com",
    "country": "Brasil",
    "currentIndustry": "aaaaaaaaaaaaa",
    "otherIndustry": "aaaaaaaaaaaaa",
    "currentOrganization": "test",
    "salary": "1234567"
  };

myObject.currentIndustry = undefined;
myObject = JSON.parse(JSON.stringify(myObject));

console.log(myObject);

  1. With es6 spread Operator:

const myObject = {
    "employeeid": "160915848",
    "firstName": "tet",
    "lastName": "test",
    "email": "test@email.com",
    "country": "Brasil",
    "currentIndustry": "aaaaaaaaaaaaa",
    "otherIndustry": "aaaaaaaaaaaaa",
    "currentOrganization": "test",
    "salary": "1234567"
};


const {currentIndustry, ...filteredObject} = myObject;
console.log(filteredObject);

Or if you can use omit() of underscore js library:

const filteredObject = _.omit(currentIndustry, 'myObject');
console.log(filteredObject);

When to use what??

If you don't wanna create a new filtered object, simply go for either option 1 or 2. Make sure you define your object with let while going with the second option as we are overriding the values. Or else you can use any of them.

hope this helps :)

Discussions

Recursively delete JSON keys
If your project is using lens, then the transform :: Plated a => (a -> a) -> a -> a function can express this operation extremely compactly. It basically says "if a is a type that can have self-similar children (aeson's Value type can contain Values through the Array and Object constructors), then rewrite all values of that type in a bottom-up fashion. However, if you're asking this question, you might want to leave lenses as "something to learn later" for the sanity of you and your team. That said, here's a code sample, which requires the lens, aeson, and lens-aeson libraries: {-# LANGUAGE OverloadedStrings #-} import Control.Lens (transform, (%~)) import Data.Aeson (Value (..), object, (.=)) import Data.Aeson.Lens (_Object) import qualified Data.HashMap.Lazy as H myObject :: Value myObject = object [ "foo" .= String "bar", "baz" .= String "quux", "yoyo" .= object [ "foo" .= (4 :: Int), "slam" .= String "jam" ] ] myObjectNoFoo :: Value myObjectNoFoo = object [ "baz" .= String "quux", "yoyo" .= object [ "slam" .= String "jam" ] ] sansFoo :: Value -> Value sansFoo = transform $ _Object %~ H.delete "foo" In action: $ ghci Foo.hs GHCi, version 8.8.4: https://www.haskell.org/ghc/ :? for help [1 of 1] Compiling Main ( Foo.hs, interpreted ) Ok, one module loaded. *Main> sansFoo myObject == myObjectNoFoo True More on reddit.com
🌐 r/haskell
7
13
September 23, 2021
remove key(s) from a json array under javascript - Stack Overflow
You can't delete from JSON, you ... the key, then stringify again. ... Well you could delete it from a string as well (with some different code), but I'd say deleting it from the object is way better and easier. ... Save this answer. ... Show activity on this post. JSON.stringify has an often overlooked parameter called the replacer. It can accept an array of key names ... More on stackoverflow.com
🌐 stackoverflow.com
How to delete JSON keys from an array with PHP? - Stack Overflow
I have the following array, and I want to be able to delete all the "phonenumber" keys and of course its value from the JSON objects. Only the keys "phonenumber" an not the whole object. How can I do More on stackoverflow.com
🌐 stackoverflow.com
October 18, 2017
Delete specific JSON keys
Hello, I’m kind of getting sloppy and I need your help. Normally I would figure this out but I have been working way too much… • I have a JSON string from a webflow module see screenshot 1: • I then convert this string to a JSON (not even sure if this is the right approach) see screenshot ... More on community.make.com
🌐 community.make.com
8
0
December 5, 2023
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-remove-element-from-json-object-in-javascript
JSON File Remove Operations in Node.js - GeeksforGeeks
January 17, 2026 - ... let jObj = { "company": ... jObj.courses; console.log(jObj); ... filter method removes a property from a JSON object by filtering key-value pairs and reconstructing the object....
🌐
Reddit
reddit.com › r/haskell › recursively delete json keys
r/haskell on Reddit: Recursively delete JSON keys
September 23, 2021 -

I'm currently working on a project that relies JSON comparison for tests instead of standard equality (yeah, I know). For particular reasons, we ignore part of the JSON when comparing between the expected and the actual value. Currently, the code is something like this:

import qualified Data.HashMap.Strict as H

deleteValues (Object o) = Object
      $ H.delete "values" -- Currently removed "values" key.
deleteValues _ = Object H.empty

We had to change our JSON and we added a new key, which we don't want to consider when testing. This key can appear on several positions, not only at the top level like values.

For example, we have something like this:

{
    "values": [],
    "info": "ok",
    "key_to_remove": 0,
    "details": null
}

Here the key_to_remove is only at the top level. But we could have something like:

{
    "values": [],
    "info": "ok",
    "key_to_remove": 1,
    "details": {
        "info": "ok",
        "key_to_remove": 2
    }
}

The nesting can keep going on, and I really would like to avoid manually traversing the object looking and deleting the key.

The idea is to remove all key_to_remove from the JSON object, independent of the position or value that it holds.


Edit: solution:

deleteKey :: Text -> Value -> Value
deleteKey k (Object o) = Object $ H.delete k (deleteKey k <$> o)
deleteKey k (Array arr) = Array (deleteKey k <$> arr)
deleteKey _ v = v
Top answer
1 of 2
12
If your project is using lens, then the transform :: Plated a => (a -> a) -> a -> a function can express this operation extremely compactly. It basically says "if a is a type that can have self-similar children (aeson's Value type can contain Values through the Array and Object constructors), then rewrite all values of that type in a bottom-up fashion. However, if you're asking this question, you might want to leave lenses as "something to learn later" for the sanity of you and your team. That said, here's a code sample, which requires the lens, aeson, and lens-aeson libraries: {-# LANGUAGE OverloadedStrings #-} import Control.Lens (transform, (%~)) import Data.Aeson (Value (..), object, (.=)) import Data.Aeson.Lens (_Object) import qualified Data.HashMap.Lazy as H myObject :: Value myObject = object [ "foo" .= String "bar", "baz" .= String "quux", "yoyo" .= object [ "foo" .= (4 :: Int), "slam" .= String "jam" ] ] myObjectNoFoo :: Value myObjectNoFoo = object [ "baz" .= String "quux", "yoyo" .= object [ "slam" .= String "jam" ] ] sansFoo :: Value -> Value sansFoo = transform $ _Object %~ H.delete "foo" In action: $ ghci Foo.hs GHCi, version 8.8.4: https://www.haskell.org/ghc/ :? for help [1 of 1] Compiling Main ( Foo.hs, interpreted ) Ok, one module loaded. *Main> sansFoo myObject == myObjectNoFoo True
2 of 2
5
deleteKeyRecursively :: Text -> Value -> Value deleteKeyRecursively key = dkr where dkr (Object map) = Object . fmap dkr $ delete key map dkr (Array vec) = Array $ fmap dkr vec dkr atom = atom That's off the top of my head, so there could definitely be problems. I no longer remember how to get GHCi to pick up my locally installed packages because cabal doesn't install libraries sanely into my user package db anymore, so I'm not able to simply test it quickly.
🌐
SingleStore
docs.singlestore.com › helios › reference › sql reference › json functions › json_delete_key
JSON_DELETE_KEY · SingleStore Helios Documentation
August 1, 2024 - Removes a key/value pair from a JSON map or array. ... keypath: A comma-separated list of dictionary keys or zero-indexed array positions that specify the path to the key to delete.
🌐
GitHub
gist.github.com › gkhays › 4fe1e6193e62b1f2cad3bd4b00f16c92
Remove an attribute or element from a JSON array during enumeration · GitHub
July 18, 2018 - JSONArray ja = loadJSONArray(); JSONObject firstJSON = ja.getJSONObject(0); Iterator<?> iter = firstJSON.keys(); for (int i = 0; i < ja.length(); i++) { JSONObject json = ja.getJSONObject(i); while (iter.hasNext()) { String key = iter.next().toString(); if (json.getString(key).equals("null")) { json.remove(key); } } } ... Exception in thread "main" java.util.ConcurrentModificationException at java.util.LinkedHashMap$LinkedHashIterator.nextNode(LinkedHashMap.java:711) at java.util.LinkedHashMap$LinkedKeyIterator.next(LinkedHashMap.java:734) at JSONKeyRemover.removeKeyWhileIterating(JSONKeyRemover.java:32) at JSONKeyRemover.main(JSONKeyRemover.java:69) I ended up copying the JSON array into a Java collection and used the JSONObject.names() method to obtain a JSONArray of keys.
🌐
GitHub
gist.github.com › 3d44c7228fa8cfe8097daa2f7e2b476c
Recursively remove json keys in an array · GitHub
Recursively remove json keys in an array · Raw · stripJSON.js · This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Find elsewhere
🌐
Pluralsight
pluralsight.com › blog › tech guides & tutorials
Delete Data from JSON Using a Key in React | Pluralsight
Use the parse function to convert ...,"1234567890"]}'; let jsonObj = JSON.parse(jsonStr); The delete operator can be used to remove a key-value pair from a JavaScript object:...
🌐
Make Community
community.make.com › questions
Delete specific JSON keys - Questions - Make Community
December 5, 2023 - Hello, I’m kind of getting sloppy and I need your help. Normally I would figure this out but I have been working way too much… • I have a JSON string from a webflow module see screenshot 1: • I then convert this string to a JSON (not even sure if this is the right approach) see screenshot 2 : What I want to achieve is to check for each json key (exemple: 2023-12-04 and 2023-12-08 etc) if those dates have already passed.
🌐
TutorialsPoint
tutorialspoint.com › remove-json-element-javascript
Remove json element - JavaScript?
November 3, 2023 - Use delete for removing object properties, splice() for removing array elements by index, and filter() for conditional removal.
🌐
GeeksforGeeks
geeksforgeeks.org › how-to-delete-an-index-from-json-object
How to delete an index from JSON Object ? | GeeksforGeeks
September 13, 2024 - In JavaScript, removing elements from a JSON object is important for modifying data structures dynamically. This object manipulation can help us to create dynamic web pages. The approaches to accomplish this task are listed and discussed below: Table of Content Using delete KeywordUsing filter Metho ... It is important to manage the state in ReactJS for building interactive user interfaces. Sometimes when we work with arrays, we need to remove an item from these arrays.
🌐
Visual Studio Marketplace
marketplace.visualstudio.com › items
JSON Keys Remover - Visual Studio Marketplace
Extension for Visual Studio Code - Removes all occurrences of selected keys(properties) from JSON.
Top answer
1 of 7
128

delete operator is used to remove an object property.

delete operator does not returns the new object, only returns a boolean: true or false.

In the other hand, after interpreter executes var updatedjsonobj = delete myjsonobj['otherIndustry']; , updatedjsonobj variable will store a boolean value.

How to remove Json object specific key and its value ?

You just need to know the property name in order to delete it from the object's properties.

delete myjsonobj['otherIndustry'];

let myjsonobj = {
  "employeeid": "160915848",
  "firstName": "tet",
  "lastName": "test",
  "email": "[email protected]",
  "country": "Brasil",
  "currentIndustry": "aaaaaaaaaaaaa",
  "otherIndustry": "aaaaaaaaaaaaa",
  "currentOrganization": "test",
  "salary": "1234567"
}
delete myjsonobj['otherIndustry'];
console.log(myjsonobj);

If you want to remove a key when you know the value you can use Object.keys function which returns an array of a given object's own enumerable properties.

let value="test";
let myjsonobj = {
      "employeeid": "160915848",
      "firstName": "tet",
      "lastName": "test",
      "email": "[email protected]",
      "country": "Brasil",
      "currentIndustry": "aaaaaaaaaaaaa",
      "otherIndustry": "aaaaaaaaaaaaa",
      "currentOrganization": "test",
      "salary": "1234567"
}
Object.keys(myjsonobj).forEach(function(key){
  if (myjsonobj[key] === value) {
    delete myjsonobj[key];
  }
});
console.log(myjsonobj);

2 of 7
22

There are several ways to do this, lets see them one by one:

  1. delete method: The most common way

const myObject = {
    "employeeid": "160915848",
    "firstName": "tet",
    "lastName": "test",
    "email": "[email protected]",
    "country": "Brasil",
    "currentIndustry": "aaaaaaaaaaaaa",
    "otherIndustry": "aaaaaaaaaaaaa",
    "currentOrganization": "test",
    "salary": "1234567"
};

delete myObject['currentIndustry'];
// OR delete myObject.currentIndustry;
  
console.log(myObject);

  1. By making key value undefined: Alternate & a faster way:

let myObject = {
    "employeeid": "160915848",
    "firstName": "tet",
    "lastName": "test",
    "email": "[email protected]",
    "country": "Brasil",
    "currentIndustry": "aaaaaaaaaaaaa",
    "otherIndustry": "aaaaaaaaaaaaa",
    "currentOrganization": "test",
    "salary": "1234567"
  };

myObject.currentIndustry = undefined;
myObject = JSON.parse(JSON.stringify(myObject));

console.log(myObject);

  1. With es6 spread Operator:

const myObject = {
    "employeeid": "160915848",
    "firstName": "tet",
    "lastName": "test",
    "email": "[email protected]",
    "country": "Brasil",
    "currentIndustry": "aaaaaaaaaaaaa",
    "otherIndustry": "aaaaaaaaaaaaa",
    "currentOrganization": "test",
    "salary": "1234567"
};


const {currentIndustry, ...filteredObject} = myObject;
console.log(filteredObject);

Or if you can use omit() of underscore js library:

const filteredObject = _.omit(currentIndustry, 'myObject');
console.log(filteredObject);

When to use what??

If you don't wanna create a new filtered object, simply go for either option 1 or 2. Make sure you define your object with let while going with the second option as we are overriding the values. Or else you can use any of them.

hope this helps :)