Skip to content

Get array info from JSON in VBA #186

@ellencrss

Description

@ellencrss

I'm trying to get JSON data and put it into a Excel Worksheet! I got this JSON data sample when use the URL + api token:

{"success":true,
	"data":
	{ "id":69,
	  "company_id":7695699,
	  "owner_id": {
             "id":11743179,
	     "name":"Allea",
             "email":"xxxx/2mail.com.br",
             "has_pic":1},
	"org_id":null,
	"name":"Teste_1",
	"first_name":"Teste_1",
	"last_name":null,
	"email_messages_count":0,
	"followers_count":1,
	"active_flag":true,
	"phone":[{
		"label":"work",
		"value":"1140028922",
		"primary":true}],
	"email":[{
		"label":"work",
		"value":"teste@mail.com",
		"primary":true}],
	"profile_id":"999999",
	"profile_type":"11"}}

I can get no-array data (like name or profile_type) without any problem, but dont know how to get array data like email, for sample. Using this VBA code:

Sub v2()
Dim ws As Worksheet
Set ws = Sheets("ver2")

Dim company_domain As String
    company_domain = "xxx"

Dim data_field_api_key As String
    data_field_api_key = "76cdc98828ab2ada0abd194c1648965274bc9d13"

'Create http get request URL
Dim personUrl As String
    personUrl = "https://" & company_domain & ".pipedrive.com/v1/persons/" & ws.[pd_person_id] & "?api_token=" & ws.[pd_your_api_token]

Set http = CreateObject("WinHttp.WinHttpRequest.5.1")

http.Open "GET", personUrl, False
http.send

'Download data for the existing deal
Dim JSON As Object
Set JSON = JsonConverter.ParseJson(http.responseText)

Dim read_data As String
Dim read_nome As String
Dim read_email As String
Dim read_profile_id As String
Dim read_profile_type As String

read_data = JSON("data")(data_field_api_key)
read_nome = JSON("data")("name")
read_email = JSON("data")("email")
read_profile_id = JSON("data")("profile_id")
read_profile_type = JSON("data")("profile_type")

'Put data in Worksheet
ws.[pd_name].Value = read_nome
ws.[pd_email].Value = read_email
ws.[pd_profile_id].Value = read_profile_id
ws.[pd_profile_type].Value = read_profile_type

End Sub

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions