go – Grabbing value from Confluence JSON response-ThrowExceptions

Exception or error:

I’m trying to grab the ID field from the JSON response of a confluence page, that data looks like this:


I’ve been looking online and my code should be working but it’s not and I’m at a loss.

package main

import (

type dataResponse struct {
    Id string `json:"id"`

func main() {

    var p dataResponse

    response, err := http.Get("https://confluence.domain.org/url/to/page/with/params"

    if err != nil {
    } else {
      data, _ := ioutil.ReadAll(response.Body)
      json.Unmarshal(data, &p)

   defer response.Body.Close()

But this isn’t returning anything. I think it has something to do with the id field being after the “results” but haven’t found a way to work with that. Edit: updated url, copied the debugging one by accident.

How to solve:

id is in an array of objects, inside results. To unmarshal a json document, your structure must match the document, that is:

type body struct {
  Results []dataResponse `json:"results"`


var doc body
json.Unmarshal(data, &doc)

You can get the id from:


Leave a Reply

Your email address will not be published. Required fields are marked *