I have a sheet where for each row in column Z there is a JSON string recovered from Twitter via TAGS.
The JSON strings in column Z all have a similar structure:
{
"hashtags": [
{
"text": "Negev_Summit",
"indices": [
172,
185
]
}
],
"symbols": [],
"user_mentions": [
{
"screen_name": "JY_LeDrian",
"name": "Jean-Yves Le Drian",
"id": 1055021191,
"id_str": "1055021191",
"indices": [
69,
80
]
}
],
"urls": [],
"media": [
{
"id": 1513588335893258200,
"id_str": "1513588335893258240",
"indices": [
271,
294
],
"media_url": "http://pbs.twimg.com/media/FQFYknkXoAAxgYd.jpg",
"media_url_https": "https://pbs.twimg.com/media/FQFYknkXoAAxgYd.jpg",
"url": "https://twitter.com/yairlapid/status/1513588345468825605",
"display_url": "pic.twitter.com/dA4cBepIh2",
"expanded_url": "https://twitter.com/yairlapid/status/1513588345468825605/photo/1",
"type": "photo",
"sizes": {
"medium": {
"w": 1024,
"h": 576,
"resize": "fit"
},
"thumb": {
"w": 150,
"h": 150,
"resize": "crop"
},
"large": {
"w": 1024,
"h": 576,
"resize": "fit"
},
"small": {
"w": 680,
"h": 383,
"resize": "fit"
}
}
}
]
}
I need to extract specific values for each JSON string in column Z and put them in columns AA, AB and AC (hashtags, user mentions, and URL's).
I've managed to achieve this with a really dirty multiple REGEXREPLACE formula but it doesn't seem logical that there is no way to fo this more efficiently:
=IFERROR("@"&JOIN(" @",SPLIT(REGEXREPLACE(REGEXREPLACE(REGEXREPLACE(REGEXREPLACE(REGEXREPLACE(REGEXEXTRACT(INDIRECT("Y"&ROW()),".*user_mentions\"":\[(.*)\],\""urls.*"),"(,\""indices\"":\[\d+,\d+\])",""),"(,\""id_str\"":\""\d+\"")",""),"(,\""id\"":\d+)",""),"(\{\""screen_name\"":\"")",""),"\"",\""name\"":\""(.){1,50}\""\}",""),",")),"")
Ideally i'm looking for a script which would parse the JSON string and extract 1 or more values from each section of the JSON. For example:
For hashtags (column AA):
=PARSEJSON(Z1, "hashtags")
Result:
#hashtag1 #hashtag2
For user_mentions (column AB):
=PARSEJSON(Z1, "user_mentions/screen_name")
Result:
@username1 @username2
Would appreciate any help sending me in the right direction.
screen_name
in a separate cell? how are you using the fetch method to get the data? – Laconism