First of all, you cannot hide individual context menu options using JSON formatting. You can only customize/hide options from command bar at the top.
You can hide "Share" option from command bar using `` as key like:
{
"key": "share",
"hide": true
}
Documentation: Command bar customization syntax reference
You can hide complete context menu from list view using two methods:
Method 1 - SharePoint OOTB:
In SharePoint list, Title column has three different variants:
- Title
- Title (linked to item)
- Title (linked to item with edit menu)
So, you can use plain "Title" column in your list view to hide context menu.
Method 2 - JSON formatting:
You can add simple JSON formatting on Title column like below to hide context menu:
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "div",
"txtContent": "@currentField"
}
While using JSON formatting, you will loose all OOTB functionality formatting for Title column including default click which open display/view form of list, you can get it back using JSON formatting on Title column like:
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "div",
"txtContent": "@currentField",
"customRowAction": {
"action": "defaultClick"
},
"attributes": {
"class": "sp-field-underline"
}
}
Update from comments:
As you are using document library, you have to apply column formatting on Name column instead of Title column: :
Format option:
Then go to "Advanced mode":
Copy-paste above JSON and click "Save":
You can apply additional styling as per your requirements. Check below documentation for more information:
- Use Column formatting in SharePoint
- JSON formatting-syntax-reference