# Conversion from JSON failed with error: Unexpected character encountered while parsing value: @. Path '' nor quering it works

**URL:** <https://forums.powershell.org/t/conversion-from-json-failed-with-error-unexpected-character-encountered-while-parsing-value-path-nor-quering-it-works/22343>\
**Category:** PowerShell Help\
**Created:** [May 22, 2023, 3:20pm UTC](https://forums.powershell.org/t/conversion-from-json-failed-with-error-unexpected-character-encountered-while-parsing-value-path-nor-quering-it-works/22343 "2023-05-22T15:20:42Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![eliassal2](https://avatars.discourse-cdn.com/v4/letter/e/3ab097/32.png) [@eliassal2](https://forums.powershell.org/u/eliassal2)\
**Post date:** [May 22, 2023, 3:20pm UTC](https://forums.powershell.org/t/conversion-from-json-failed-with-error-unexpected-character-encountered-while-parsing-value-path-nor-quering-it-works/22343/1 "2023-05-22T15:20:42Z")

</div>

Hi, I am using Invoke-RestMethod to retreive dtails of repositories from Azur devops server as follows  
`$ListProject = (Invoke-RestMethod -Uri $OrgUrl -Method Get -UseDefaultCredential -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)})`

Operation goes through, I can see the value of $ListProject as follows

```auto
count value
----- -----
   28 {@{objectId=b79db4fd12b3a0207fe1116ee8168e14b81d7d74; gitObjectType=tree; commitId=ee76cb8621e26604742bc5321ad3a3302bb22ddf; path=/; isFolder=True; url=https://azuredevops2k19.salam.net/Sierac-Utilities…

```

but when I try to query as json  
$ListProject.value.[objectId, path]  
I get

> ParserError: Array index expression is missing or not valid

Trying to convert json to string or table using  
`$results = ConvertFrom-JSON $ListProject`

I get the following error

> ConvertFrom-Json: Conversion from JSON failed with error: Unexpected character encountered while parsing value: @. Path ‘’, line 0, position 0.

So how can I parse the returned json?

---

<div class="post-metadata">

**Author:** ![neemobeer](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/neemobeer/32/4087_2.png) [@neemobeer](https://forums.powershell.org/u/neemobeer)\
**Post date:** [May 22, 2023, 4:13pm UTC](https://forums.powershell.org/t/conversion-from-json-failed-with-error-unexpected-character-encountered-while-parsing-value-path-nor-quering-it-works/22343/2 "2023-05-22T16:13:37Z")

</div>

Invoke-RestMethod returns an array of objects, not strictly JSON. You can use Invoke-WebRequest and pass the resulting content or rawcontent to ConvertFrom-JSON

---

<div class="post-metadata">

**Author:** ![eliassal2](https://avatars.discourse-cdn.com/v4/letter/e/3ab097/32.png) [@eliassal2](https://forums.powershell.org/u/eliassal2)\
**Post date:** [May 22, 2023, 5:46pm UTC](https://forums.powershell.org/t/conversion-from-json-failed-with-error-unexpected-character-encountered-while-parsing-value-path-nor-quering-it-works/22343/3 "2023-05-22T17:46:06Z")

</div>

Thanks neemobeer, I did use Invoke-WebRequest

> $ListProjectWebRequest = (Invoke-WebRequest -Uri $OrgUrl -Method Get -UseDefaultCredential -Headers @{Authorization=(“Basic {0}” -f $base64AuthInfo)})

Then I convert as follows

> $ListProjectWebRequestCJ = ConvertFrom-JSON $ListProjectWebRequest

when I run $ListProjectWebRequestCJ by itself, I get the exact same output as before , I am really dont know how I can parse this as I am not sure if it is json or string. I tried also using the flag -AsHashtable as follows

> $ListProjectWebRequestCJHT = ConvertFrom-JSON $ListProjectWebRequest -AsHashtable

when I run $ListProjectWebRequestCJHT by itself it gives

Name Value

* * *

count 28  
value {b79db4fd12b3a0207fe1116ee8168e14b81d7d74, 3e759b75bf455ac809d0987d369aab89137b5689, 5c8b41ed093ed2f58057f8ed6edb9bc4ac906a51, b77670a17a97a8cb61434496f43d8371f695991b…}

which seems contains only objectIds not other properties in the json file

 ![image](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/2X/6/6bf0b4e90f4b1498a6910d2a75eb066ba0f2f852.png)

---

<div class="post-metadata">

**Author:** ![neemobeer](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/neemobeer/32/4087_2.png) [@neemobeer](https://forums.powershell.org/u/neemobeer)\
**Post date:** [May 22, 2023, 6:34pm UTC](https://forums.powershell.org/t/conversion-from-json-failed-with-error-unexpected-character-encountered-while-parsing-value-path-nor-quering-it-works/22343/4 "2023-05-22T18:34:14Z")

</div>

Sometimes the data is nested when it’s returned. $ListProjectWebRequestCJ.value has the data you want

---

<div class="post-metadata">

**Author:** ![eliassal2](https://avatars.discourse-cdn.com/v4/letter/e/3ab097/32.png) [@eliassal2](https://forums.powershell.org/u/eliassal2)\
**Post date:** [May 22, 2023, 7:06pm UTC](https://forums.powershell.org/t/conversion-from-json-failed-with-error-unexpected-character-encountered-while-parsing-value-path-nor-quering-it-works/22343/5 "2023-05-22T19:06:44Z")

</div>

You are correct, I did that and it containes the details I need but is it a collection or an array?  
I did the following and got some good results

> $ListProjectWebRequestCJ.value | Select Id, name, lastUpdateTime, url | Format-Table

Another auestion pleqse . how can I find all properties to display as the properties I was able to use I found it in postman

---

<div class="post-metadata">

**Author:** ![neemobeer](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/neemobeer/32/4087_2.png) [@neemobeer](https://forums.powershell.org/u/neemobeer)\
**Post date:** [May 22, 2023, 7:51pm UTC](https://forums.powershell.org/t/conversion-from-json-failed-with-error-unexpected-character-encountered-while-parsing-value-path-nor-quering-it-works/22343/6 "2023-05-22T19:51:45Z")

</div>

You can always pass a variable (object) to Get-Member to see what type it is as well it’s property types. To find properties from an API you will have to consult the specific API documentation.

---

<div class="post-metadata">

**Author:** ![eliassal2](https://avatars.discourse-cdn.com/v4/letter/e/3ab097/32.png) [@eliassal2](https://forums.powershell.org/u/eliassal2)\
**Post date:** [May 23, 2023, 9:51am UTC](https://forums.powershell.org/t/conversion-from-json-failed-with-error-unexpected-character-encountered-while-parsing-value-path-nor-quering-it-works/22343/7 "2023-05-23T09:51:38Z")

</div>

OK got it, I was able to play with the objects. Here is a piece of the returned values

“value”: [  
{  
“id”: “0d1c66ba-d842-4a7e-ae1a-10ef9e4279e9”,  
“name”: “session-3-demo.git”,  
“url”: “[https://azuredevops2k19.salam.net/Sierac-Utilities/6e767fad-8a74-40d8-900a-3673b5be8049/\_apis/git/repositories/0d1c66ba-d842-4a7e-ae1a-10ef9e4279e9](https://azuredevops2k19.salam.net/Sierac-Utilities/6e767fad-8a74-40d8-900a-3673b5be8049/_apis/git/repositories/0d1c66ba-d842-4a7e-ae1a-10ef9e4279e9)”,  
**“project”** : {  
“id”: “6e767fad-8a74-40d8-900a-3673b5be8049”,  
“name”: “dotNet Projects”,  
“description”: “Group misc net projects”,  
“state”: “wellFormed”,  
“revision”: 75,  
“visibility”: “private”,  
“lastUpdateTime”: “2021-01-08T12:29:41.537Z”  
},  
“defaultBranch”: “refs/heads/main”,  
“size”: 5374,  
“remoteUrl”: “[https://azuredevops2k19.salam.net/Sierac-Utilities/dotNet%20Projects/\_git/session-3-demo.git](https://azuredevops2k19.salam.net/Sierac-Utilities/dotNet%20Projects/_git/session-3-demo.git)”,  
“isDisabled”: false  
},

After transforming the returned value by Invoke-webrequest to hashtable, I can issue

$ListReposUrldotNetProjectsCJ.value | Select Id, name

and get right results, however when I try to access any propoerty in the project nested array I get nothing like this

> $ListReposUrldotNetProjectsCJ.value | Select Id, name, project.id

I get nothing in the last outputfield field

---

<div class="post-metadata">

**Author:** ![neemobeer](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/neemobeer/32/4087_2.png) [@neemobeer](https://forums.powershell.org/u/neemobeer)\
**Post date:** [May 23, 2023, 1:41pm UTC](https://forums.powershell.org/t/conversion-from-json-failed-with-error-unexpected-character-encountered-while-parsing-value-path-nor-quering-it-works/22343/8 "2023-05-23T13:41:48Z")

</div>

Pretty sure your data is accessible like so

 ![image](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/2X/5/5eacb61bb69ff7b6563f758935073a12f10877c5.png)

---

<div class="post-metadata">

**Author:** ![eliassal2](https://avatars.discourse-cdn.com/v4/letter/e/3ab097/32.png) [@eliassal2](https://forums.powershell.org/u/eliassal2)\
**Post date:** [May 23, 2023, 2:30pm UTC](https://forums.powershell.org/t/conversion-from-json-failed-with-error-unexpected-character-encountered-while-parsing-value-path-nor-quering-it-works/22343/9 "2023-05-23T14:30:54Z")

</div>

Correct, doing

> $ListReposUrldotNetProjectsCJ.value[0].project

I get all properties for the nested project properties  
also doing

> $ListReposUrldotNetProjectsCJ.value[0].project.lastUpdateTime

I get the right value, however, when I issue

> $ListReposUrldotNetProjectsCJ.value | Select Id, name, project.id

I get nothing under project.id

id name project.id

* * *

0d1c66ba-d842-4a7e-ae1a-10ef9e4279e9 session-3-demo.git  
8766f993-1a06-4517-b11e-1db7eb6a599f BuildingMS-Play.Common  
88dc7723-6900-420a-8bb6-22e2114f7e08 BuildingMS-Play.Inventory  
19f1d481-7339-4251-887c-263462238e0c BuildingMS-Play.Catalog  
b5b551eb-930f-476e-9d68-3a7aec9af8df BuildingMS-Play.Contracts  
654a2259-21f3-4538-96b5-65774166dec9 Async.Await.Demo  
7e8b26b1-3664-4225-a647-7de040f0e4fd UnitTesting-Julio  
8901fcc5-a936-4ca5-ae01-96df213fd444 Session-3-Demo  
1978d282-6a9a-497c-8706-a5b886628644 NET5\_REST\_API\_Tutorial  
3268c2c3-5d3c-44f7-8e68-a8b71391b586 Tech-Session-2  
f5f6332d-ed07-403f-bc2e-c11274854dfb CommanderGQL  
df2376b3-7229-4951-9384-ee972f5b431c dotNet Projects

---

<div class="post-metadata">

**Author:** ![eliassal2](https://avatars.discourse-cdn.com/v4/letter/e/3ab097/32.png) [@eliassal2](https://forums.powershell.org/u/eliassal2)\
**Post date:** [May 23, 2023, 2:34pm UTC](https://forums.powershell.org/t/conversion-from-json-failed-with-error-unexpected-character-encountered-while-parsing-value-path-nor-quering-it-works/22343/10 "2023-05-23T14:34:29Z")

</div>

when I issue  
$ListReposUrldotNetProjectsCJ.value | Select Id, name, project  
I get the whole json under project

 ![image](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/2X/2/2d8f6d8d20cc1539377c312138623f2ab2ed004e.png)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/1X/385e4f9fe133561ad30a814262fe0e0ae6bc3ef0.png) [@system](https://forums.powershell.org/u/system)\
**Post date:** [February 10, 2024, 5:34pm UTC](https://forums.powershell.org/t/conversion-from-json-failed-with-error-unexpected-character-encountered-while-parsing-value-path-nor-quering-it-works/22343/12 "2024-02-10T17:34:03Z")

</div>

Closed on February 10, 2024, 5:34pm UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
