WhatTheClown
WhatTheClown

Reputation: 486

How do I get a JSON request but get a certain part of it?

I have this current Python code...

import requests
import json
response = json.loads(requests.get("https://meta.multimc.org/v1/net.minecraftforge/index.json").text)

But I can't find out how to get a specific bit instead of the whole JSON page.

I'd like to get versions.version on that URL but I can't find out what piece of code to add to make it do that.

Upvotes: 0

Views: 147

Answers (1)

Nidal Barada
Nidal Barada

Reputation: 393

You iterate over the versions array in response['versions'] and add each version to a list.

import request
import json

response = json.loads(requests.get("https://meta.multimc.org/v1/net.minecraftforge/index.json").text)

versions=[]
for i in range(len(response['versions'])):
    versions.append(response['versions'][i]['version'])

Upvotes: 1

Related Questions