opened
jbpAtEy
username_0
Background: I see a similar issue was brought up previously in https://github.com/PowerShell/PowerShell/issues/3705
Background: I am using PS 7.x (currently 7.1.0) to export and read data from something known as PingFederate via API that outputs JSON

Below is output from a test lab. The screen grabs are from a previous test when i thought the issue was the vendor of PingFederate
Please note that the expected behavior is that both pulls are treated as JSON.

Notes that Test Object 2, the string, has the following part causing the error
```
"EmployeeID":{"source":{"type":"AUTHENTICATION_POLICY_CONTRACT"},"value":"EmployeeID"},"EmployeeId":{"source":{"type":"AUTHENTICATION_POLICY_CONTRACT"},"value":"EmployeeID"
```

RFCs that show JSON is Case Sensitive:
JSON RFC (current 2020 11 19) https://tools.ietf.org/html/rfc8259
JSON Data Type RFC (current 2020 11 19) https://www.ietf.org/rfc/rfc4627.txt

## From PowerShell Window
```
PowerShell 7.1.0
Copyright (c) Microsoft Corporation.

https://aka.ms/powershell
Type 'help' to get help.

PS C:\temp\EYSAFEPISCT> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.1.0
PSEdition                      Core
GitCommitId                    7.1.0
OS                             Microsoft Windows 10.0.17763
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

PS C:\temp\EYSAFEPISCT> $PFFTECreds = Get-Credential

PowerShell credential request
Enter your credentials.
User: PIAdmin
Password for user PIAdmin: **********

PS C:\temp\EYSAFEPISCT> $headers = @{} # headers variable
PS C:\temp\EYSAFEPISCT> $headers.Add("X-Xsrf-Header","PingFederate")
PS C:\temp\EYSAFEPISCT> $PFFTEURL2 = "https://pingui.lab.ey:9999/pf-admin-api/v1/idp/spConnections?page=2&numberPerPage=1"
PS C:\temp\EYSAFEPISCT> $PFFTEURL1 = "https://pingui.lab.ey:9999/pf-admin-api/v1/idp/spConnections?page=1&numberPerPage=1"
PS C:\temp\EYSAFEPISCT> $testObj1 = Invoke-RESTMethod -Uri $PFFTEURL2 -Credential $PFFTECreds -Headers $headers -SslProtocol Tls12 -SkipCertificateCheck -ErrorVariable errors
PS C:\temp\EYSAFEPISCT> $testObj2 = Invoke-RESTMethod -Uri $PFFTEURL1 -Credential $PFFTECreds -Headers $headers -SslProtocol Tls12 -SkipCertificateCheck -ErrorVariable errors
PS C:\temp\EYSAFEPISCT> Get-Member -InputObject $testObj1

   TypeName: System.Management.Automation.PSCustomObject

Name        MemberType   Definition
----        ----------   ----------
Equals      Method       bool Equals(System.Object obj)
GetHashCode Method       int GetHashCode()
GetType     Method       type GetType()
ToString    Method       string ToString()
items       NoteProperty Object[] items=System.Object[]

PS C:\temp\EYSAFEPISCT> Get-Member -InputObject $testObj2

   TypeName: System.String

Name                 MemberType            Definition
----                 ----------            ----------
Clone                Method                System.Object Clone(), System.Object ICloneable.Clone()
CompareTo            Method                int CompareTo(System.Object value), int CompareTo(string strB), int IComparable.CompareTo(System.Object obj), int IComparable[string].Compar…
Contains             Method                bool Contains(string value), bool Contains(string value, System.StringComparison comparisonType), bool Contains(char value), bool Contains(c…
CopyTo               Method                void CopyTo(int sourceIndex, char[] destination, int destinationIndex, int count)
EndsWith             Method                bool EndsWith(string value), bool EndsWith(string value, System.StringComparison comparisonType), bool EndsWith(string value, bool ignoreCas…
EnumerateRunes       Method                System.Text.StringRuneEnumerator EnumerateRunes()
Equals               Method                bool Equals(System.Object obj), bool Equals(string value), bool Equals(string value, System.StringComparison comparisonType), bool IEquatabl…
GetEnumerator        Method                System.CharEnumerator GetEnumerator(), System.Collections.IEnumerator IEnumerable.GetEnumerator(), System.Collections.Generic.IEnumerator[ch…
GetHashCode          Method                int GetHashCode(), int GetHashCode(System.StringComparison comparisonType)
GetPinnableReference Method                System.Char&, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e GetPinnableReference()
GetType              Method                type GetType()
GetTypeCode          Method                System.TypeCode GetTypeCode(), System.TypeCode IConvertible.GetTypeCode()
IndexOf              Method                int IndexOf(char value), int IndexOf(char value, int startIndex), int IndexOf(char value, System.StringComparison comparisonType), int Index…
IndexOfAny           Method                int IndexOfAny(char[] anyOf), int IndexOfAny(char[] anyOf, int startIndex), int IndexOfAny(char[] anyOf, int startIndex, int count)
Insert               Method                string Insert(int startIndex, string value)
IsNormalized         Method                bool IsNormalized(), bool IsNormalized(System.Text.NormalizationForm normalizationForm)
LastIndexOf          Method                int LastIndexOf(char value), int LastIndexOf(char value, int startIndex), int LastIndexOf(char value, int startIndex, int count), int LastIn…
LastIndexOfAny       Method                int LastIndexOfAny(char[] anyOf), int LastIndexOfAny(char[] anyOf, int startIndex), int LastIndexOfAny(char[] anyOf, int startIndex, int cou…
Normalize            Method                string Normalize(), string Normalize(System.Text.NormalizationForm normalizationForm)
PadLeft              Method                string PadLeft(int totalWidth), string PadLeft(int totalWidth, char paddingChar)
PadRight             Method                string PadRight(int totalWidth), string PadRight(int totalWidth, char paddingChar)
Remove               Method                string Remove(int startIndex, int count), string Remove(int startIndex)
Replace              Method                string Replace(string oldValue, string newValue, bool ignoreCase, cultureinfo culture), string Replace(string oldValue, string newValue, Sys…
Split                Method                string[] Split(char separator, System.StringSplitOptions options), string[] Split(char separator, int count, System.StringSplitOptions optio…
StartsWith           Method                bool StartsWith(string value), bool StartsWith(string value, System.StringComparison comparisonType), bool StartsWith(string value, bool ign…
Substring            Method                string Substring(int startIndex), string Substring(int startIndex, int length)
ToBoolean            Method                bool IConvertible.ToBoolean(System.IFormatProvider provider)
ToByte               Method                byte IConvertible.ToByte(System.IFormatProvider provider)
ToChar               Method                char IConvertible.ToChar(System.IFormatProvider provider)
ToCharArray          Method                char[] ToCharArray(), char[] ToCharArray(int startIndex, int length)
ToDateTime           Method                datetime IConvertible.ToDateTime(System.IFormatProvider provider)
ToDecimal            Method                decimal IConvertible.ToDecimal(System.IFormatProvider provider)
ToDouble             Method                double IConvertible.ToDouble(System.IFormatProvider provider)
ToInt16              Method                short IConvertible.ToInt16(System.IFormatProvider provider)
ToInt32              Method                int IConvertible.ToInt32(System.IFormatProvider provider)
ToInt64              Method                long IConvertible.ToInt64(System.IFormatProvider provider)
ToLower              Method                string ToLower(), string ToLower(cultureinfo culture)
ToLowerInvariant     Method                string ToLowerInvariant()
ToSByte              Method                sbyte IConvertible.ToSByte(System.IFormatProvider provider)
ToSingle             Method                float IConvertible.ToSingle(System.IFormatProvider provider)
ToString             Method                string ToString(), string ToString(System.IFormatProvider provider), string IConvertible.ToString(System.IFormatProvider provider)
ToType               Method                System.Object IConvertible.ToType(type conversionType, System.IFormatProvider provider)
ToUInt16             Method                ushort IConvertible.ToUInt16(System.IFormatProvider provider)
ToUInt32             Method                uint IConvertible.ToUInt32(System.IFormatProvider provider)
ToUInt64             Method                ulong IConvertible.ToUInt64(System.IFormatProvider provider)
ToUpper              Method                string ToUpper(), string ToUpper(cultureinfo culture)
ToUpperInvariant     Method                string ToUpperInvariant()
Trim                 Method                string Trim(), string Trim(char trimChar), string Trim(Params char[] trimChars)
TrimEnd              Method                string TrimEnd(), string TrimEnd(char trimChar), string TrimEnd(Params char[] trimChars)
TrimStart            Method                string TrimStart(), string TrimStart(char trimChar), string TrimStart(Params char[] trimChars)
Chars                ParameterizedProperty char Chars(int index) {get;}
Length               Property              int Length {get;}

PS C:\temp\EYSAFEPISCT>
```

![labtest-screen1](https://user-images.githubusercontent.com/38132319/99686136-4bf50b00-2a51-11eb-9e5d-205362b92078.png)
![labtest-screen2](https://user-images.githubusercontent.com/38132319/99686138-4bf50b00-2a51-11eb-9bd9-59d156f838a7.png)
JSON auto-parse is case insensitive
issue
created
mklement0
username_1
Not allowing case variations of the same property name in a single object is by design, given that member access in PowerShell is case-insensitive (by default, a `[pscustomobject]` object [graph] is constructed, where such case variations aren't permitted).

The workaround is implied by the error message you get:

```powershell
PS> '{ "foo": 1, "Foo": 2 }' | ConvertFrom-Json
ConvertFrom-Json: Cannot convert the JSON string because it contains keys with different casing. 
Please use the -AsHashTable switch instead. 
The key that was attempted to be added to the existing key 'foo' was 'Foo'.
```

Note:

* `-AsHashTable` returns a hashtable with case-_sensitive_ key lookups, allowing you to target `.foo` and `.Foo` separately, whether or not the input had properties whose names are case variations; this can be surprising, given that hashtable _literals_ in PowerShell always use case-_insensitive_ lookups.

* You also need `-AsHashTable` if your JSON input has a property name that is the _empty string_:

  * ` '{ "": 1}' | ConvertFrom-Json -AsHashTable`

* `-AsHashTable` isn't available in Windows PowerShell.
comment
created
jbpAtEy
username_0
HI @username_1 

I'm not trying to convert from JSON to anything. i am trying to handle it as JSON. this fails. JSON standard is case sensitive. if JSON is to be supported it should be in an object that is capable of handling the JSON standard. 

thank you.
comment
created
mklement0
username_1
You _are_ converting it to a `[pscustomobject]` graph, which is what  `Invoke-RESTMethod` does for you _implicitly_.
Another way of putting it: it has a `ConvertFrom-Json` _built in_.

Unlike with an _explicit_ `ConvertFrom-Json` call, however, there's currently no way to pass `-AsHashTable` to `Invoke-RestMethod`, so you are indeed limited with respect to what JSON you can process.

At least for now, the workaround for you is to use [`Invoke-WebRequest`](https://docs.microsoft.com/powershell/module/microsoft.powershell.utility/invoke-webrequest) and to pass the `.Content` value (the JSON _text_) of the response object to `ConvertFrom-Json -AsHashtable`.
comment
created
mklement0
username_1
For symmetry, it would make sense to me to enhance `Invoke-RestMethod` to also support an `-AsHashTable` switch, but I suggest you create a new issue of type "Feature Request/Idea" and present a focused case there.
comment