-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Description
Steps to reproduce
$data = @"
{
"firstName": "Bill",
"Firstname": "Bob",
"lastName": "Gates"
}
"@
$json = $data | ConvertFrom-Json
Expected behavior
Convert JSON data, containing 3 pairs of key/value, with same key name "firstName" but with a different case:
- firstName: with the letter "f" in lowercase and the letter "N" in upper case
- Firstname: with the letter "F" in uppercase and the letter "n" in lowercase
Actual behavior
Exception thrown:
ConvertFrom-Json : Cannot convert the JSON string because a dictionary that was converted from the string contains the duplicated keys 'firstName' and 'Firstname'.
At line:8 char:17
$json = $data | ConvertFrom-Json
CategoryInfo : InvalidOperation: (:) [ConvertFrom-Json], InvalidOperationException
FullyQualifiedErrorId : DuplicateKeysInJsonString,Microsoft.PowerShell.Commands.ConvertFromJsonCommand
As PowerShell is case insensitive, it considers the second key "Firstname", with a different case, as a duplicate key.
JSON allows to have same key name but with different case
Environment data
Name Value
PSVersion 5.1.14393.1066
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.14393.1066
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1