How to turn on and off the multiple metadata formats for JSON in SharePoint Server 2013

SharePoint 2013
 

Applies to: SharePoint Server 2013

Topic Last Modified: 2016-12-16

Summary:Learn how to turn on and off the multiple metadata formats for the JavaScript Object Notation (JSON) feature in a SharePoint Server 2013 environment.

The multiple metadata formats can be turned on in a SharePoint Server 2013 with Service Pack 1 (SP1) environment.

The multiple metadata formats are multiple verbosity levels of metadata returned by OData when JSON is requested and added to the OData endpoint on SharePoint Server 2013 with Service Pack 1 (SP1) and SharePoint Online. For additional information about the different formats available, see JSON Light support in REST SharePoint API released. You can also turn on this feature for your on-premises environments. You use a Windows PowerShell script to turn on the feature across your farm. The script turns on the feature across all existing sites and any new sites that you create.

NoteNote:
Windows PowerShell is the only way to turn on the multiple metadata formats feature in SharePoint Server 2013 with Service Pack 1 (SP1).
NoteNote:
For changes in the script to take effect, an app pool recycle is required and immediately happens in the script.

To turn on the multiple metadata formats feature by using a Windows PowerShell script
  1. Verify that you have the following memberships:

    • The securityadmin fixed server role on the SQL Server instance.

    • The db_owner fixed database role on all databases that are to be updated.

    • The Administrators group on the server on which you are running Windows PowerShell cmdlets.

    • It is a good idea that you are at the computer that is running the SharePoint Central Administration website.

    • All computers must have SharePoint Server 2013 with Service Pack 1 (SP1) installed as well as WCF Data Services 5.6 installed and in the Global Access Cache (GAC). You can get WCF Data Services installed by running the prerequisite installer that was updated with SharePoint Server 2013 with Service Pack 1 (SP1), or you can download the MSI directly at WCF Data Services and install it by using the following command: WcfDataServices.exe /quiet GacRuntime=1.

      NoteNote:
      If you use the WCF graphical installer, you must choose Option to place the assemblies in the GAC folder or you'll not have the features that are available to you.
    • You must read about_Execution_Policies

    An administrator can use the Add-SPShellAdmin cmdlet to grant permissions to use SharePoint 2013 cmdlets.

    NoteNote:
    If you do not have permissions, contact your setup administrator or SQL Server administrator to request permissions. For additional information about Windows PowerShell permissions, see Permissions and Add-SPShellAdmin.
  2. Use a text editor, such as Notepad, to create a text file by pasting the following code into the file.

    $configOwnerName = "JSONLightDependentAssembly"
    
    $spWebConfigModClass ="Microsoft.SharePoint.Administration.SPWebConfigModification"
    
    $dependentAssemblyPath ="configuration/runtime/*[local-name()='assemblyBinding' and namespace-uri()='urn:schemas-microsoft-com:asm.v1']"
    
    $dependentAssemblyNameStart ="*[local-name()='dependentAssembly'][*/@name='"
    $dependentAssemblyNameEnd = "'][*/@publicKeyToken='31bf3856ad364e35'][*/@culture='neutral']"
    
    $dependentAssemblyValueStart = "<dependentAssembly><assemblyIdentity name='"
    $dependentAssemblyValueEnd ="' publicKeyToken='31bf3856ad364e35' culture='neutral' /><bindingRedirect oldVersion='5.0.0.0' newVersion='5.6.0.0' /></dependentAssembly>"
    
    $edmAssemblyName ="Microsoft.Data.Edm"
    $odataAssemblyName ="Microsoft.Data.Odata"
    $dataServicesAssemblyName ="Microsoft.Data.Services"
    $dataServicesClientAssemblyName ="Microsoft.Data.Services.Client"
    $spatialAssemblyName ="System.Spatial"
    
    
    $assemblyNamesArray = $edmAssemblyName,$odataAssemblyName,$dataServicesAssemblyName,$dataServicesClientAssemblyName, $spatialAssemblyName
    
    
    Add-PSSnapin Microsoft.SharePoint.Powershell
    $webService = [Microsoft.SharePoint.Administration.SPWebService]::ContentService
    
    
    ################ Adds individual assemblies ####################
    
    For ($i=0; $i -lt 5; $i++)  
    {
        echo "Adding Assembly..."$assemblyNamesArray[$i]
    
        $dependentAssembly = New-Object $spWebConfigModClass
        $dependentAssembly.Path=$dependentAssemblyPath
        $dependentAssembly.Sequence =0 # First item to be inserted
        $dependentAssembly.Owner = $configOwnerName
        $dependentAssembly.Name =$dependentAssemblyNameStart + $assemblyNamesArray[$i] + $dependentAssemblyNameEnd
        $dependentAssembly.Type = 0 #Ensure Child Node
        $dependentAssembly.Value = $dependentAssemblyValueStart + $assemblyNamesArray[$i] + $dependentAssemblyValueEnd
    
        $webService.WebConfigModifications.Add($dependentAssembly)
    }
    
    ###############################################################
    
    echo "Saving Web Config Modification"
    
    $webService.Update()
    $webService.ApplyWebConfigModifications()
    
    echo "Update Complete"
    
     
    
    
  3. Save the file and add the .ps1 extension, such as JSON.ps1.

    NoteNote:
    You can use a different file name, but you must save the file as an ANSI-encoded text file with a .ps1 extension.
  4. Start the SharePoint 2013 Management Shell.

    • For Windows Server 2008 R2:

      • On the Start menu, click All Programs, click Microsoft SharePoint 2013 Products, and then click SharePoint 2013 Management Shell.

    • For Windows Server 2012:

      • On the Start screen, click SharePoint 2013 Management Shell.

    • If SharePoint 2013 Management Shell is not on the Start screen:

    • Right-click Computer, click All apps, and then click SharePoint 2013 Management Shell.

    For more information about how to interact with Windows Server 2012, see Common Management Tasks and Navigation in Windows Server 2012.

  5. Change to the directory where you saved the file.

  6. At the Windows PowerShell command prompt, type the following command.

    ./JSON.ps1
    

If you find the need to remove the feature from your installation, you can do so easily by running a script to remove the entry that was placed. This disables the feature across all computers and forces all requests to use the verbose metadata format again.

To turn off the multiple metadata formats feature by using a Windows PowerShell script
  1. Verify that you have the following memberships:

    • The securityadmin fixed server role on the SQL Server instance.

    • The db_owner fixed database role on all databases that are to be updated.

    • The Administrators group on the server on which you are running Windows PowerShell cmdlets.

    • You must read about_Execution_Policies (https://go.microsoft.com/fwlink/p/?LinkId=193050).

    An administrator can use the Add-SPShellAdmin cmdlet to grant permissions to use SharePoint 2013 cmdlets.

    NoteNote:
    If you do not have permissions, contact your setup administrator or SQL Server administrator to request permissions. For additional information about Windows PowerShell permissions, see Permissions and Add-SPShellAdmin.
  2. Use a text editor, such as Notepad, to create a text file by pasting the following code into the file.

    $configOwnerName = "JSONLightDependentAssembly"
    
    Add-PSSnapin Microsoft.SharePoint.Powershell
    $webService = [Microsoft.SharePoint.Administration.SPWebService]::ContentService
    
    $webService.WebConfigModifications | ft 
    
    $configs = $webService.WebConfigModifications | Where-Object {$_.Owner -eq $configOwnerName }
    foreach ($config in $configs) {
    
       echo "Removing Assembly..."$config.Name
    
       $webService.WebConfigModifications.Remove($config)
    }
    
    echo "Saving Web Config Modification"
    
    if($configs.length -ne 0)
    {
    $webService.Update()
    $webService.ApplyWebConfigModifications()
    }
    
    echo "Update Complete" 
    
    
  3. Save the file and add the .ps1 extension, such as JSON_Remove.ps1.

    NoteNote:
    You can use a different file name, but you must save the file as an ANSI-encoded text file with a .ps1 extension.
  4. Start the SharePoint 2013 Management Shell.

    • For Windows Server 2008 R2:

      • On the Start menu, click All Programs, click SharePoint 2013 Products, and then click SharePoint 2013 Management Shell.

    • For Windows Server 2012:

      • On the Start screen, click SharePoint 2013 Management Shell.

        If SharePoint 2013 Management Shell is not on the Start screen:

      • Right-click Computer, click All apps, and then click SharePoint 2013 Management Shell.

    For more information about how to interact with Windows Server 2012, see Common Management Tasks and Navigation in Windows Server 2012.

  5. Change to the directory where you saved the file.

  6. At the Windows PowerShell command prompt, type the following command:

    ./JSON_Remove.ps1
    

Show: