T
T
Tayrus02021-04-06 17:54:26
Python
Tayrus0, 2021-04-06 17:54:26

How to work with such json?

I make an API request and get this response:

[{
    'pl': 'Категория',
    'vl': 'Техника для красоты и здоровья',
    'p': 'category',
    'v': 15060
}, {
    'pl': 'Тип сделки',
    'vl': 'Продажа',
    'p': 'type',
    'v': 'sell'
}, {
    'pl': 'Вся Беларусь',
    'vl': 'Гомельская',
    'p': 'region',
    'v': 2
}, {
    'pl': 'Город / Район',
    'vl': 'Гомель',
    'p': 'area',
    'v': '5'
}, {
    'pl': 'Тип оплаты',
    'vl': 'Цена',
    'p': 'remuneration_type',
    'v': '1'
}, {
    'pl': 'Тип',
    'vl': 'Электромассажеры',
    'p': 'health_equipment_type',
    'v': '60'
}, {
    'pl': 'Производитель',
    'vl': 'Другой',
    'p': 'health_equipment_brand',
    'v': '100'
}, {
    'pl': 'Запчасть',
    'vl': '-',
    'p': 'appliances_spare_part',
    'v': False
}, {
    'pl': 'Состояние',
    'vl': 'Б/у',
    'p': 'condition',
    'v': '1'
}, {
    'pl': 'Товары с Куфар Доставкой',
    'vl': 'Да',
    'p': 'delivery_enabled',
    'v': True
}, {
    'pl': 'Товары с Куфар Оплатой',
    'vl': 'Да',
    'p': 'safedeal_enabled',
    'v': True
}, {
    'pl': 'Возможна доставка',
    'vl': '-',
    'p': 'delivery_pro',
    'v': False
}, {
    'pl': 'Возможна рассрочка',
    'vl': '-',
    'p': 'installment_pro',
    'v': False
}, {
    'pl': 'Возможен обмен',
    'vl': '-',
    'p': 'possible_exchange',
    'v': False
}]


I want to get the value
'pl': 'Город / Район',
    'vl': 'Гомель',
    'p': 'area',
    'v': '5'


But I can't get to it, because when I unpack it from the list, all I have left is this
{'pl': 'Тип сделки', 'vl': 'Продажа', 'p': 'type', 'v': 'sell'}


How to deal with this json?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir Kuts, 2021-04-06
@Tayrus0

This is not json )
But if you want to get data, then for example, by the key 'vl': 'Gomel':

next(filter(lambda x: x['vl'] == 'Гомель', a))
# {'pl': 'Город / Район', 'vl': 'Гомель', 'p': 'area', 'v': '5'}

where in a is your structure

E
Evgeniy _, 2021-04-06
@GeneD88

Well, here you can iterate all the elements in json and if pl == "City / District", then work with this element further.

for el in jsn:
    if el['pl'] == 'Город / Район':
        print(e)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question