Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Python help

  • 09-03-2018 8:17pm
    #1
    Registered Users, Registered Users 2 Posts: 1,363 ✭✭✭


    Hello,

    I'm struggling with handling a JSON response from an app that I'm playing about with it.

    I have written a little app that pulls back a profile from Companies House in the uk.

    For this question, I'm using a google company and I get this response:

    {
    "company_number": "10197747",
    "company_name": "GOOGLE ADWORD EUROPE SERVICES LTD",
    "has_charges": false,
    "company_status": "active",
    "undeliverable_registered_office_address": false,
    "has_insolvency_history": false,
    "etag": "eb63a58d61840d804e7adaaddc179fe87ee29d1b",
    "jurisdiction": "england-wales",
    "registered_office_address": {
    "address_line_2": "Suite 33854 Advantage Business Centre",
    "address_line_1": "132-134 Great Ancoats Street",
    "locality": "Manchester",
    "postal_code": "M4 6DE",
    "country": "England"
    },
    "type": "ltd",
    "accounts": {
    "next_made_up_to": "2018-05-31",
    "overdue": false,
    "next_due": "2019-02-28",
    "last_accounts": {
    "type": "dormant",
    "period_start_on": "2016-05-25",
    "made_up_to": "2017-05-31",
    "period_end_on": "2017-05-31"
    },
    "accounting_reference_date": {
    "month": "05",
    "day": "31"
    },
    "next_accounts": {
    "period_start_on": "2017-06-01",
    "due_on": "2019-02-28",
    "overdue": false,
    "period_end_on": "2018-05-31"
    }
    },
    "date_of_creation": "2016-05-25",
    "confirmation_statement": {
    "overdue": false,
    "next_due": "2018-04-27",
    "next_made_up_to": "2018-04-13",
    "last_made_up_to": "2017-04-13"
    },
    "links": {
    "self": "/company/10197747",
    "filing_history": "/company/10197747/filing-history",
    "officers": "/company/10197747/officers",
    "persons_with_significant_control": "/company/10197747/persons-with-significant-control"
    },
    "sic_codes": [
    "82990"
    ],
    "registered_office_is_in_dispute": false,
    "can_file": true
    }

    I get this via Python with:


    r = requests.get('https://api.companieshouse.gov.uk/company/10197747', auth=HTTPBasicAuth('secret_key', ''))
    company_data = json.loads(r.text)

    So I have a data structiure called company_data

    However, I want to start pulling individual elements that are a 'nested dict' (I don't know the real term.

    I can query top level strings (such as "type" or "sic_codes") but I can't get "officers" which are nested under "links".

    Can someone help?


Comments

  • Moderators, Computer Games Moderators Posts: 4,282 Mod ✭✭✭✭deconduo


    ezra_ wrote: »
    Hello,

    I'm struggling with handling a JSON response from an app that I'm playing about with it.

    I have written a little app that pulls back a profile from Companies House in the uk.

    For this question, I'm using a google company and I get this response:

    {
    "company_number": "10197747",
    "company_name": "GOOGLE ADWORD EUROPE SERVICES LTD",
    "has_charges": false,
    "company_status": "active",
    "undeliverable_registered_office_address": false,
    "has_insolvency_history": false,
    "etag": "eb63a58d61840d804e7adaaddc179fe87ee29d1b",
    "jurisdiction": "england-wales",
    "registered_office_address": {
    "address_line_2": "Suite 33854 Advantage Business Centre",
    "address_line_1": "132-134 Great Ancoats Street",
    "locality": "Manchester",
    "postal_code": "M4 6DE",
    "country": "England"
    },
    "type": "ltd",
    "accounts": {
    "next_made_up_to": "2018-05-31",
    "overdue": false,
    "next_due": "2019-02-28",
    "last_accounts": {
    "type": "dormant",
    "period_start_on": "2016-05-25",
    "made_up_to": "2017-05-31",
    "period_end_on": "2017-05-31"
    },
    "accounting_reference_date": {
    "month": "05",
    "day": "31"
    },
    "next_accounts": {
    "period_start_on": "2017-06-01",
    "due_on": "2019-02-28",
    "overdue": false,
    "period_end_on": "2018-05-31"
    }
    },
    "date_of_creation": "2016-05-25",
    "confirmation_statement": {
    "overdue": false,
    "next_due": "2018-04-27",
    "next_made_up_to": "2018-04-13",
    "last_made_up_to": "2017-04-13"
    },
    "links": {
    "self": "/company/10197747",
    "filing_history": "/company/10197747/filing-history",
    "officers": "/company/10197747/officers",
    "persons_with_significant_control": "/company/10197747/persons-with-significant-control"
    },
    "sic_codes": [
    "82990"
    ],
    "registered_office_is_in_dispute": false,
    "can_file": true
    }

    I get this via Python with:


    r = requests.get('https://api.companieshouse.gov.uk/company/10197747', auth=HTTPBasicAuth('secret_key', ''))
    company_data = json.loads(r.text)

    So I have a data structiure called company_data

    However, I want to start pulling individual elements that are a 'nested dict' (I don't know the real term.

    I can query top level strings (such as "type" or "sic_codes") but I can't get "officers" which are nested under "links".

    Can someone help?

    You probably want to do something like:
    print(company_data["links"]["officers"])
    


  • Registered Users, Registered Users 2 Posts: 1,363 ✭✭✭ezra_


    deconduo wrote: »
    You probably want to do something like:
    print(company_data["links"]["officers"])
    

    Very simple! I had my syntax wrong, thank you


Advertisement