Skip to main content
Question

Strava API - Get Activity output format

  • November 11, 2024
  • 2 replies
  • 79 views

Forum|alt.badge.img

Hi,

The JSON format I get out of the API when I extract multiple Activities is not following JSON standards as it seems. I am not an expert not a dev. But if I pretty print it and save the output, and load it for further analysis, it says the file format is not valid.

I've tried to debut it and indeed I get “multiple JSON root elements”.

Any idea? :)

Thx for your help!

2 replies

Jan_Mantau
Superuser
Forum|alt.badge.img+26
  • Superuser
  • 895 replies
  • November 11, 2024

Maybe your analysis prgram has a bug or the json got distorted in the printing and saving process. The activities endpoint creates a json array, a single root is not expected here.


ActivityFix
Superuser
Forum|alt.badge.img+24
  • Superuser
  • 232 replies
  • November 12, 2024

How are you getting the JSON output? The general format for the returned array should look something like this, where the entire output is enclosed in square brackets [] indicating an array, and each activity is enclosed in curly braces {} as an entry in the array.

[
  {
    "resource_state" : 2,
    "athlete" : {
      "id" : 1,
      "resource_state" : 1
    },
    "name" : "Activity #1",
    "other_fields" : "values"
  },
  {
    "resource_state" : 2,
    "athlete" : {
      "id" : 1,
      "resource_state" : 1
    },
    "name" : "Activity #2",
    "other_fields" : "values"
  }
]

If you are seeing multiple root elements, maybe you missed copying the enclosing square brackets around the whole thing? You could also try running the JSON through https://jsonlint.com/ to see what problems it highlights.


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept, you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings