B
B
Brenly2020-05-25 14:08:18
Python
Brenly, 2020-05-25 14:08:18

How to change response encoding from woocommerce rest api?

With the help of flask and a python script, I receive data, but the response looks like this:

spoiler
[{"id":1053,"name":"\u041d\u0430\u043b\u0438\u0447\u043d\u0438\u043a 3D \u0412\u0435\u043d\u0433\u0435 \u0440\u0435\u043b\u044c\u0435\u0444\u043d\u044b\u0439","slug":"nalichnik-3d-venge-relefnyj","permalink":"https:\/\/site.ru.ru\/product\/nalichnik-3d-venge-relefnyj\/","date_created":"2017-02-08T16:07:38","date_created_gmt":"2017-02-08T11:07:38","date_modified":"2020-05-07T11:28:40","date_modified_gmt":"2020-05-07T06:28:40","type":"simple","status":"publish","featured":false,"catalog_visibility":"visible","description":"","short_description":"","sku":"17452","price":"135.00","regular_price":"135.00","sale_price":"","date_on_sale_from":null,"date_on_sale_from_gmt":null,"date_on_sale_to":null,"date_on_sale_to_gmt":null,"price_html":"135.00 р.<\/span><\/span>","on_sale":false,"purchasable":true,"total_sales":1,"virtual":false,"downloadable":false,"downloads":[],"download_limit":-1,"download_expiry":-1,"external_url":"","button_text":"","tax_status":"taxable","tax_class":"","manage_stock":false,"stock_quantity":null,"stock_status":"instock","backorders":"no","backorders_allowed":false,"backordered":false,"sold_individually":false,"weight":"","dimensions":{"length":"","width":"","height":""},"shipping_required":true,"shipping_taxable":true,"shipping_class":"","shipping_class_id":0,"reviews_allowed":true,"average_rating":"0.00","rating_count":0,"related_ids":[],"upsell_ids":[],"cross_sell_ids":[],"parent_id":0,"purchase_note":"","categories":[{"id":474,"name":"\u0422\u0435\u0441\u0442\u043e\u0432\u0430\u044f\u0414\u043e\u0447\u0435\u0440\u043d\u044f\u044f1","slug":"testovayadochernyaya1"}],"tags":[],"images":[{"id":364,"date_created":"2017-02-06T17:43:11","date_created_gmt":"2017-02-06T07:43:11","date_modified":"2017-02-06T17:43:11","date_modified_gmt":"2017-02-06T07:43:11","src":"https:\/\/site.ru.ru\/wp-content\/uploads\/2017\/02\/unavailable-3.jpg","name":"unavailable","alt":""}],"attributes":[],"default_attributes":[],"variations":[],"grouped_products":[],"menu_order":0,"meta_data":[],"_links":{"self":[{"href":"https:\/\/site.ru.ru\/wp-json\/wc\/v3\/products\/1053"}],"collection":[{"href":"https:\/\/site.ru\/wp-json\/wc\/v3\/products"}]}}]

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Karbivnichy, 2020-05-25
@Brenly

The question is not entirely clear, but I can assume this:

import json

with open('json.txt') as file:
  json_data = json.loads(file.read())

print(json.dumps(json_data,ensure_ascii=False))

[{"id": 1053, "name": "Наличник 3D Венге рельефный", "slug": "nalichnik-3d-venge-relefnyj", "permalink": "https://site.ru.ru/product/nalichnik-3d-venge-relefnyj/", "date_created": "2017-02-08T16:07:38", "date_created_gmt": "2017-02-08T11:07:38", "date_modified": "2020-05-07T11:28:40", "date_modified_gmt": "2020-05-07T06:28:40", "type": "simple", "status": "publish", "featured": false, "catalog_visibility": "visible", "description": "", "short_description": "", "sku": "17452", "price": "135.00", "regular_price": "135.00", "sale_price": "", "date_on_sale_from": null, "date_on_sale_from_gmt": null, "date_on_sale_to": null, "date_on_sale_to_gmt": null, "price_html": "135.00 р.</span></span>", "on_sale": false, "purchasable": true, "total_sales": 1, "virtual": false, "downloadable": false, "downloads": [], "download_limit": -1, "download_expiry": -1, "external_url": "", "button_text": "", "tax_status": "taxable", "tax_class": "", "manage_stock": false, "stock_quantity": null, "stock_status": "instock", "backorders": "no", "backorders_allowed": false, "backordered": false, "sold_individually": false, "weight": "", "dimensions": {"length": "", "width": "", "height": ""}, "shipping_required": true, "shipping_taxable": true, "shipping_class": "", "shipping_class_id": 0, "reviews_allowed": true, "average_rating": "0.00", "rating_count": 0, "related_ids": [], "upsell_ids": [], "cross_sell_ids": [], "parent_id": 0, "purchase_note": "", "categories": [{"id": 474, "name": "ТестоваяДочерняя1", "slug": "testovayadochernyaya1"}], "tags": [], "images": [{"id": 364, "date_created": "2017-02-06T17:43:11", "date_created_gmt": "2017-02-06T07:43:11", "date_modified": "2017-02-06T17:43:11", "date_modified_gmt": "2017-02-06T07:43:11", "src": "https://site.ru.ru/wp-content/uploads/2017/02/unavailable-3.jpg", "name": "unavailable", "alt": ""}], "attributes": [], "default_attributes": [], "variations": [], "grouped_products": [], "menu_order": 0, "meta_data": [], "_links": {"self": [{"href": "https://site.ru.ru/wp-json/wc/v3/products/1053"}], "collection": [{"href": "https://site.ru/wp-json/wc/v3/products"}]}}]

P
Pychev Anatoly, 2020-05-25
@pton

You are looking at json encoded string
Run it through any json decoder and get human readable data with decoded characters
5ecbb9c91a0ed447313030.png

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question