# Extract string from json

**URL:** <https://forums.powershell.org/t/extract-string-from-json/15635>\
**Category:** PowerShell Help\
**Created:** [February 12, 2021, 6:17am UTC](https://forums.powershell.org/t/extract-string-from-json/15635 "2021-02-12T06:17:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![abel](https://avatars.discourse-cdn.com/v4/letter/a/2acd7d/32.png) [@abel](https://forums.powershell.org/u/abel)\
**Post date:** [February 12, 2021, 6:17am UTC](https://forums.powershell.org/t/extract-string-from-json/15635/1 "2021-02-12T06:17:49Z")

</div>

Greetings all,

I’m trying to use the google translate api to translate words and save the content as a text or csv.

I’m having a hard time extracting the json content returned from invoke-Restmethod. It appears the translated data is in the “SyncRoot” property.

Any help would be appreciated

&nbsp;

```
$Text = "Hi there!", "My name is John.", "What is your name?"," Cool!"
$TargetLanguage = "es"
$Uri = "https://translate.googleapis.com/translate_a/single?client=gtx&sl=auto&tl=$($TargetLanguage)&dt=t&q=$Text".
$Response = Invoke-RestMethod -Uri $Uri -Method Get
$Response.Content
```

---

<div class="post-metadata">

**Author:** ![ralphmwr](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/ralphmwr/32/1064_2.png) [@ralphmwr](https://forums.powershell.org/u/ralphmwr)\
**Post date:** [February 12, 2021, 7:00am UTC](https://forums.powershell.org/t/extract-string-from-json/15635/2 "2021-02-12T07:00:34Z")

</div>

Admittedly, I’m very unfamiliar with this API. Having said that Invoke-RestMethod is already parsing the JSON into objects. It appears to me that the first object’s syncroot property has all the text you are looking for but interspersed with integers. So you can do this to get the data you want in an array of strings:

```
$Response[0] | 
    Select-Object -ExpandProperty syncroot | 
        Where-Object {$_.gettype().Name -eq "String"}
```

&nbsp;

---

<div class="post-metadata">

**Author:** ![sam-boutros](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/sam-boutros/32/5_2.png) [@sam-boutros](https://forums.powershell.org/u/sam-boutros)\
**Post date:** [February 12, 2021, 9:42am UTC](https://forums.powershell.org/t/extract-string-from-json/15635/3 "2021-02-12T09:42:37Z")

</div>

```
$Text = "Hi there!", "My name is John.", "What is your name?"," Cool!"
$TargetLanguage = "es"
$Uri = "https://translate.googleapis.com/translate_a/single?client=gtx&sl=auto&tl=$($TargetLanguage)&dt=t&q=$Text"
$Response = Invoke-RestMethod -Uri $Uri -Method Get

$Response[0].SyncRoot | foreach { $_[0] }
```

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:27pm UTC](https://forums.powershell.org/t/extract-string-from-json/15635/4 "2024-05-16T20:27:51Z")

</div>


