0

I have this JSON response from httparty:

{
    "banks": [{
        "sync_frequency": null,
        "code": null,
        "uuid": "2ac14818-59fb-50cf-b3e4-3bddcdfefcae",
        "documents_type": [],
        "color": "003d8f",
        "id": 479,
        "available_transfer_mechanisms": [],
        "auth_mechanism": "credentials",
        "capabilities": ["document"],
        "transfer_beneficiary_types": [],
        "available_auth_mechanisms": ["credentials"],
        "beta": true,
        "months_to_fetch": null,
        "urls": ["https://login.ionos.fr", "https://my.ionos.fr"],
        "siret": null,
        "hidden": false,
        "charged": true,
        "slug": "1&1",
        "categories": [],
        "name": "1&1"
    }, {
        "sync_frequency": null,
        "code": null,
        "uuid": "fabe9547-ba74-5f8c-a790-f5ecc7c4626b",
        "documents_type": [],
        "color": "ffa500",
        "id": 492,
        "available_transfer_mechanisms": [],
        "auth_mechanism": "credentials",
        "capabilities": ["document"],
        "transfer_beneficiary_types": [],
        "available_auth_mechanisms": ["credentials"],
        "beta": true,
        "months_to_fetch": null,
        "urls": ["http://www.avantages-entreprises.com"],
        "siret": null,
        "hidden": false,
        "charged": true,
        "slug": "ACE",
        "categories": [],
        "name": "aceos"
    }, {
        "sync_frequency": null,
        "code": null,
        "uuid": "5f778b18-d10e-5ffd-98a9-ed61d1d39f9b",
        "account_types": ["perp", "madelin", "lifeinsurance"],
        "documents_type": [],
        "color": "005090",
        "id": 406,
        "available_transfer_mechanisms": [],
        "auth_mechanism": "credentials",
        "capabilities": ["bankwealth", "document", "bank"],
        "transfer_beneficiary_types": [],
        "available_auth_mechanisms": ["credentials"],
        "beta": false,
        "months_to_fetch": null,
        "urls": ["https://identification.adis-assurances.com", "https://www.agipi.com", "https://connexion.adis-assurances.com"],
        "siret": null,
        "hidden": false,
        "charged": true,
        "slug": "AGI",
        "categories": [],
        "name": "Agipi"
    }]
}

And i try to get all the "name" values like "1&1", "aceos", "Agipi", etc...

Any idea how to get them ? Thanks

1
  • What you have posted is an invalid ruby. Commented Nov 21, 2019 at 10:32

1 Answer 1

2

That looks like an uncomplete JSON response.

Try with JSON.parse, [] and map:

require 'json'

JSON.parse(foo)['banks'].map { |e| e['name'] } # ["1&1", "aceos", "Agipi"]
Sign up to request clarification or add additional context in comments.

2 Comments

yes JSON response from httparty sorry for my mistake. When i put the code in my controller I have the error "no implicit conversion of HTTParty::Response into String". Got it, I added .to_s in my request.
It seems you have to use parsed_response. Try with data.parsed_response['banks'] ....

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.