0

I try to parse JSON data using Regex. I want to get values of "name", "street", "lat" and "lon". This formula to get their values:

  • get name :

    =REGEXEXTRACT(REGEXREPLACE(JSON!$A$1,char(10)&"|"&char(34)&"|\s{2,}",""),"name:(.*?),street")

  • get street :

    =REGEXEXTRACT(REGEXREPLACE(JSON!$A$1,char(10)&"|"&char(34)&"|\s{2,}",""),"street:(.*?)},location")

  • get lan and lon:

    =REGEXEXTRACT(REGEXREPLACE(JSON!$A$1,char(10)&"|"&char(34)&"|\s{2,}",""),"lat:(.*?),lon")

    =REGEXEXTRACT(REGEXREPLACE(JSON!$A$1,char(10)&"|"&char(34)&"|\s{2,}",""),"lon:(.*?)},city")

My problem: i don't know to get the next data in column E until column L.

My sheet: https://docs.google.com/spreadsheets/d/1QaCT0X8iw6OjfzrPXPTc-r_HNscHIOQl5N9BBJjaaaY/edit#gid=1163290419

1
  • When the values are retrieved from JSON object, I thought that to use the custom function created by Google Apps Script might be suitable. So I proposed it. But if that was not the direction you expect, I apologize. Commented Dec 16, 2020 at 0:10

1 Answer 1

1

In your situation, I thought that to use a custom function created by Google Apps Script might be suitable. So in this answer, I would like to propose to achieve your goal using the custom function.

Sample script:

Please copy and paste the following script to the script editor of the Google Spreadsheet, and please put =SAMPLE((JSON!$A1)) to a cell. By this, each value are parsed and put to each cell of a row.

const SAMPLE = value => [JSON.parse(value).result.flatMap(({place_info: {name, street}, location: {lat, lon}}) => [name, street, lat, lon])];

Result:

enter image description here

Note:

  • In your sample Spreadsheet, there are 2 name2,street2,lat2,lon2. I thought that 2nd one might be name3,street3,lat3,lon3.

References:

Sign up to request clarification or add additional context in comments.

2 Comments

awesome, thanks a lot. i think that is so complicated if i use regex to parse the json data.
@d'natsu Thank you for replying. I'm glad your issue was resolved. Thank you, too.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.