Function outputs a different object type

I have a function that creates an authentication header for OAuth 2 authentication. The header itself is quite simple: it just has one key pair.

Inside the function, the header is a hashtable. When the hashtable is read by the calling expression, it has become an object. By converting them both to JSON I can see that an empty string has been inserted before the array, and so the object has become an array object.

You can see this clearly in the output:

"Authorization": "Bearer  xyzabc123"

Inside the function, the object just has the part inside the {} and is a hashtable. How did it get the extra “”?

As an extra problem, this happens if I request a token interactively. In EXACTLY the same function, if I request the token non-interactively, the object is returned as a hashtable and the receiving expression works fine.

seems like there is an empty input which makes the hashtable an array with first input as empty and second one the token detail.

That’s exactly right. I had a Read-Host “Press Enter”, which created an empty string in the pipeline.

Does that solve your problem ? Can I close this thread ?

@AirPowerShell98 please share the code portion that creates this JSON

Yes, please close. It was the “Read-Host” that created a blank string in the pipeline. I added | Out-Null and everything works as expected.