{"id":24844,"date":"2019-12-16T09:00:46","date_gmt":"2019-12-16T00:00:46","guid":{"rendered":"https:\/\/www.techscore.com\/blog\/?p=24844"},"modified":"2019-12-16T17:02:39","modified_gmt":"2019-12-16T08:02:39","slug":"better-way-handling-json-data-in-python","status":"publish","type":"post","link":"https:\/\/www.techscore.com\/blog\/2019\/12\/16\/better-way-handling-json-data-in-python\/","title":{"rendered":"Python\u3067JSON\u30c7\u30fc\u30bf\u3092\u6271\u3046\u5de5\u592b"},"content":{"rendered":"

\u3053\u308c\u306f TECHSCORE Advent Calendar 2019<\/a> \u306e16\u65e5\u76ee\u306e\u8a18\u4e8b\u3067\u3059\u3002<\/p>\n

Python\u3067JSON\u30c7\u30fc\u30bf\u3092\u6271\u3046<\/h2>\n

\u6700\u8fd1\u3067\u306f\u30de\u30a4\u30af\u30ed\u30b5\u30fc\u30d3\u30b9\u3060\u306a\u3093\u3060\u3068\u3001\u5916\u90e8\u30b5\u30fc\u30d3\u30b9\u306eHTTP\u306eAPI\u3092\u547c\u3073\u51fa\u3057\u3001JSON\u30c7\u30fc\u30bf\u3092\u6271\u3046\u6a5f\u4f1a\u306f\u5c11\u306a\u304f\u306a\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n

Python\u3067\u306fjson\u30d1\u30c3\u30b1\u30fc\u30b8\u3092\u5229\u7528\u3057\u3066dict(\u8f9e\u66f8)\u306b\u5909\u63db\u3057\u3066\u5229\u7528\u3059\u308b\u3053\u3068\u304c\u591a\u3044\u306e\u3067\u306f\u306a\u3044\u3067\u3057\u3087\u3046\u304b\u3002<\/p>\n

json_data = \"\"\"{\n    \"name\": \"taro\",\n    \"age\": 20\n}\"\"\"\n\nuser = json.loads(json_data)\nprint(user[\"name\"])  # \"taro\"\nprint(user[\"age\"])   # 20\n\n# get\u3092\u4f7f\u3063\u305f\u30a2\u30af\u30bb\u30b9\n# \u7b2c2\u5f15\u6570\u306b\u30c7\u30d5\u30a9\u30eb\u30c8\u5024\u3092\u6307\u5b9a\u3067\u304d\u308b(\u672a\u6307\u5b9a\u306e\u5834\u5408\u306fNone)\nprint(user.get(\"name\"))  # \"taro\"\nprint(user.get(\"age\"))   # 20<\/code><\/pre>\n

dict\u306e\u8981\u7d20\u3092\u53d6\u5f97\u3059\u308b\u5834\u5408\u306b\u306f\u3001get\u3092\u4f7f\u7528\u3059\u308b\u3068\u30ad\u30fc\u304c\u5b58\u5728\u3057\u306a\u304b\u3063\u305f\u5834\u5408\u3067\u3082KeyError\u304c\u767a\u751f\u305b\u305a\u3001\u6307\u5b9a\u306e\u5024\u3092\u8fd4\u3059\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u306a\u306e\u3067\u500b\u4eba\u7684\u306b\u306fget\u3092\u597d\u3093\u3067\u4f7f\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n

\u968e\u5c64\u304c\u6df1\u3044\u30d7\u30ed\u30d1\u30c6\u30a3\u306b\u30a2\u30af\u30bb\u30b9\u3059\u308b\u5834\u5408\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002dict\u304c\u30cd\u30b9\u30c8\u3057\u3066\u3044\u304f\u69cb\u9020\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n

json_data = \"\"\"{\n    \"name\": \"taro\",\n    \"age\": 20,\n    \"home\": {\n        \"zip_code\": \"0000000\",\n        \"city\": \"Osaka\"\n    }\n}\"\"\"\n\nuser = json.loads(json_data)\nprint(user.get(\"home\").get(\"zip_code\"))  # \"0000000\"\nprint(user.get(\"home\").get(\"city\"))      # \"Osaka\"<\/code><\/pre>\n

\u30d6\u30e9\u30b1\u30c3\u30c8\u306b\u3057\u3066\u3082get\u306b\u3057\u3066\u3082\u3001\u30b7\u30f3\u30d7\u30eb\u306a\u30c7\u30fc\u30bf\u3067\u3042\u308c\u3070\u554f\u984c\u306b\u306f\u306a\u308a\u307e\u305b\u3093\u304c\u3001\u968e\u5c64\u304c\u6df1\u304f\u306a\u308b\u3068\u5197\u9577\u306a\u611f\u3058\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n

object\u3063\u307d\u304f\u30a2\u30af\u30bb\u30b9\u3057\u305f\u3044<\/h2>\n

\u30d6\u30e9\u30b1\u30c3\u30c8\u3084get\u3092\u4f7f\u3063\u305f\u30a2\u30af\u30bb\u30b9\u3067\u306f\u306a\u304f\u3001\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3068\u5c5e\u6027\u306e\u3088\u3046\u306a .(dot) \u3092\u4f7f\u7528\u3057\u3066\u30c7\u30fc\u30bf\u3092\u5229\u7528\u3057\u305f\u3044\u3067\u3059\u3002\u5148\u307b\u3069\u306e\u4f8b\u3060\u3068\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u4f7f\u3044\u65b9\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n

json_data = \"\"\"{ ... }\"\"\"\n\nuser = # ...\u306a\u3093\u304b\u826f\u3044\u611f\u3058\u306e\u51e6\u7406\n\nprint(user.home.zip_code)  # \"0000000\" \u3068\u8868\u793a\u3055\u308c\u3066\u6b32\u3057\u3044\nprint(user.home.city)      # \"Osaka\"   \u3068\u8868\u793a\u3055\u308c\u3066\u6b32\u3057\u3044<\/code><\/pre>\n

\u3053\u308c\u306f\u5b9f\u969b\u3088\u304f\u3042\u308b\u8a71\u3063\u307d\u304f\u3001\u30b0\u30b0\u308b\u3068\u8272\u3005\u3068\u3084\u308a\u65b9\u304c\u51fa\u3066\u304d\u307e\u3059\u3002<\/p>\n

\u4f8b\u3048\u3070\u3001dict\u3092\u7d99\u627f\u3057\u3066\u5c5e\u6027\u304c\u6709\u308b\u304b\u306e\u3088\u3046\u306b\u632f\u308b\u821e\u3046\u30af\u30e9\u30b9\u3092\u5b9a\u7fa9\u3059\u308b\u65b9\u6cd5\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n

class ObjectLike(dict):\n    # __getattr__ \u306f\u5c5e\u6027\u304c\u306a\u304b\u3063\u305f\u5834\u5408\u306b\u5b9f\u884c\u3055\u308c\u308b\u7279\u6b8a\u30e1\u30bd\u30c3\u30c9\u3067\u3001dict.get\u3092\u5229\u7528\u3059\u308b\u3088\u3046\u306b\u3059\u308b\n    __getattr__ = dict.get\n\nuser = ObjectLike(name=\"taro\", age=20)\n\n# dict\u306e\u30b5\u30d6\u30af\u30e9\u30b9\u306a\u306e\u3067 [] \u3084 get \u3067\u8981\u7d20\u3092\u53d6\u5f97\u3067\u304d\u308b\nprint(user.get(\"name\"))  # \"taro\"\nprint(user.get(\"age\"))   # 20\n\n# \u3061\u3083\u3093\u3068dot notation\u304c\u3067\u304d\u307e\u3059\nprint(user.name)     # \"taro\"\nprint(user.age)      # 20<\/code><\/pre>\n

\u30b7\u30f3\u30d7\u30eb\u306b\u30a2\u30af\u30bb\u30b9\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\u306d\u3002<\/p>\n

json\u30d1\u30c3\u30b1\u30fc\u30b8\u3068\u4e00\u7dd2\u306b\u4f7f\u3046<\/h2>\n

\u3053\u306e ObjectLike \u3092JSON\u306e\u8aad\u307f\u53d6\u308a\u306e\u969b\u306b\u3082\u5229\u7528\u3057\u307e\u3059\u3002<\/p>\n

json.loads \u306b\u306f object_hook\u3068\u3044\u3046\u5f15\u6570\u304c\u3042\u308a\u3001JSON\u306eObject\u3092\u51e6\u7406\u3059\u308b\u969b\u306e\u30d5\u30c3\u30af\u3092\u4ed5\u8fbc\u3080\u3053\u3068\u304c\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002dict \u3092\u53d7\u3051\u53d6\u3063\u3066\u4f55\u3089\u304b\u306e\u5024\u3092\u8fd4\u3059\u95a2\u6570\u3067\u3042\u308c\u3070\u826f\u3044\u306e\u3067 ObjectLike \u3092\u305d\u306e\u307e\u307e\u4f7f\u7528\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n

import json\n\nclass ObjectLike(dict):\n    __getattr__ = dict.get\n\njson_data = \"\"\"{\n    \"name\": \"taro\",\n    \"age\": 20,\n    \"home\": {\n        \"zip_code\": \"0000000\",\n        \"city\": \"Osaka\"\n    }\n}\"\"\"\n\nuser = json.loads(json_data, object_hook=ObjectLike)\n\nprint(type(user))            # \nprint(user.name)             # \"taro\"\nprint(user.home.city)        # \"Osaka\"\nprint(user.home.prefecture)  # None (\u5b58\u5728\u3057\u306a\u3044\u30ad\u30fc\u306a\u306e\u3067)<\/code><\/pre>\n

\u826f\u3044\u611f\u3058\u306b\u306a\u3063\u3066\u304d\u307e\u3057\u305f\u3002<\/p>\n

JSON\u5074\u306eCamelCase\u306b\u5bfe\u5fdc\u3059\u308b<\/h2>\n

JSON\u306e\u30ad\u30fc\u540d\u3067\u306f CamelCase \uff08\u3042\u308b\u3044\u306fmixedCase\uff09\u306b\u306a\u3063\u3066\u3044\u308b\u3053\u3068\u3082\u307e\u307e\u3042\u308a\u307e\u3059\u3002\u4e00\u65b9\u3067\u3001Python\u306e\u30b3\u30fc\u30c7\u30a3\u30f3\u30b0\u306b\u304a\u3044\u3066\u5c5e\u6027\u540d\u306f snake_case \u304c\u63a8\u5968\u3055\u308c\u3066\u3044\u307e\u3059\uff08\u95a2\u6570\u3084\u5909\u6570\u306e\u540d\u524d \u2014 pep8-ja 1.0 \u30c9\u30ad\u30e5\u30e1\u30f3\u30c8<\/a>\uff09\u3002<\/p>\n

ObjectLike \u306e\u5c5e\u6027\u3068\u3057\u3066\u306f snake_case \u3067\u30a2\u30af\u30bb\u30b9\u3067\u304d\u308b\u3088\u3046\u306b\u3057\u305f\u3044\u3067\u3059\u306d\u3002\u5c5e\u6027\u30a2\u30af\u30bb\u30b9\u306e\u969b\u306b\u90fd\u5ea6 case \u306e\u78ba\u8a8d\u3092\u3059\u308b\u306e\u306f\u5b09\u3057\u304f\u306a\u3044\u306e\u3067\u3001JSON\u306e\u51e6\u7406\u6642\u306b\u30ad\u30fc\u3092\u5168\u3066 snake_case \u306b\u5909\u63db\u3059\u308b\u3088\u3046\u306b\u3057\u3066\u307f\u307e\u3059\u3002\u5b9f\u88c5\u306f\u96d1\u3067\u3059\u304c\u3001\u3053\u3093\u306a\u611f\u3058\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n

import json\nimport re # \u6b63\u898f\u8868\u73fe\u3092\u4f7f\u7528\u3059\u308b\u306e\u3067\u5fc5\u8981\u3067\u3059\n\nclass ObjectLike(dict):\n    __getattr__ = dict.get\n\ndef camel2snake(word):\n    # \u5927\u6587\u5b57\u306e\u76f4\u524d\u306b `_` \u3092\u4ed8\u4e0e\n    # -> \u5c0f\u6587\u5b57\u306b\u5909\u63db\n    # -> \u5148\u982d\u306e `_` \u3092\u9664\u53bb\uff08\u6700\u521d\u5927\u6587\u5b57\u3060\u3068\u3064\u3044\u3066\u3057\u307e\u3046\u305f\u3081\uff09\n    return re.sub(\"([A-Z])\", \"_\\\\1\", word).lower().lstrip(\"_\")\n\ndef c2s_hook(d):\n    # \u30ad\u30fc\u3092snake_case\u306b\u5909\u63db\u3057\u305f\u8f9e\u66f8\u3092\u4f5c\u6210\u3057\u3001ObjectLike\u306b\u3059\u308b\n    converted = {camel2snake(key): value for key, value in d.items()}\n    return ObjectLike(converted)\n\njson_data = \"\"\"{\n    \"name\": \"taro\",\n    \"age\": 20,\n    \"home\": {\n        \"zipCode\": \"0000000\",\n        \"city\": \"Osaka\"\n    }\n}\"\"\"\n\nuser = json.loads(json_data, object_hook=c2s_hook)\n\nprint(user.home.zipCode)   # None\nprint(user.home.zip_code)  # \"0000000\"\n<\/code><\/pre>\n

\u5143\u306eJSON\u30ad\u30fc\u306f zipCode \u3067\u3059\u304c\u3001\u5909\u63db\u3057\u305f\u306e\u3067 user.home.zip_code \u3067\u30c7\u30fc\u30bf\u304c\u53d6\u5f97\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\u3002 \u9006\u306b user.home.zipCode \u3067\u306f\u30ad\u30fc\u304c\u5b58\u5728\u3057\u306a\u3044\u305f\u3081 None \u304c\u8fd4\u3063\u3066\u304f\u308b\u3088\u3046\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n

\u3053\u308c\u3067\u3051\u3063\u3053\u3046\u73fe\u5b9f\u7684\u306b\u4f7f\u3048\u308b\u7bc4\u56f2\u306b\u306a\u3063\u305f\u6c17\u304c\u3057\u307e\u3059\u3002<\/p>\n

\u8ab2\u984c\uff1a\u9014\u4e2d\u306e\u5c5e\u6027\u304c\u306a\u3044\u3068\u30a8\u30e9\u30fc\u306b\u306a\u308b<\/h2>\n

JSON\u30c7\u30fc\u30bf\u3092\u3088\u3057\u306a\u306b\u6271\u3048\u308b\u3088\u3046\u306b\u306a\u3063\u3066\u304d\u305f\u306e\u3067\u3059\u304c\u3001\u307e\u3060\u89e3\u6c7a\u3067\u304d\u3066\u3044\u306a\u3044\u554f\u984c\u304c\u3042\u308a\u307e\u3059\u3002
\n\u4f8b\u3048\u3070\u9593\u9055\u3063\u305f\u5c5e\u6027\u3078\u30a2\u30af\u30bb\u30b9\u3092\u3057\u3066\u3057\u307e\u3063\u305f\u5834\u5408\u3084\u3001\u305d\u3082\u305d\u3082\u30c7\u30fc\u30bf\u304c\u306a\u304b\u3063\u305f\u5834\u5408\u306a\u3069\u3001\u30c1\u30a7\u30a4\u30f3\u3057\u3066\u3044\u308b\u9014\u4e2d\u306e\u5c5e\u6027\u304c\u6b20\u843d\u3057\u3066\u3057\u307e\u3046\u3068\u30a8\u30e9\u30fc\u306b\u306a\u308a\u307e\u3059\u3002\uff08API\u306e\u4ed5\u69d8\u306b\u3088\u3063\u3066\u306f\u5c5e\u6027\u304c\u3042\u3063\u305f\u308a\u306a\u304b\u3063\u305f\u308a\u3057\u307e\u3059\u3088\u306d\uff1f<\/p>\n

import json\n\nclass ObjectLike(dict):\n    __getattr__ = dict.get\n\n# home\u304c\u306a\u304f\u306a\u3063\u3066\u3057\u307e\u3063\u305f\njson_data = \"\"\"{\n    \"name\": \"taro\",\n    \"age\": 20\n}\"\"\"\n\nuser = json.loads(json_data, object_hook=ObjectLike)\n\nprint(user.home.city)  # AttributeError: 'NoneType' object has no attribute 'city'<\/code><\/pre>\n

\u3053\u308c\u306f user.home \u304c None \u3067\u3042\u308a None \u306b\u5bfe\u3057\u3066 city \u3068\u3044\u3046\u5c5e\u6027\u304c\u306a\u3044\u306e\u3067\u767a\u751f\u3057\u307e\u3059\u3002<\/p>\n

\u56de\u907f\u7b56\u304c\u306a\u3044\u3053\u3068\u306f\u306a\u3044\u306e\u3067\u3059\u304c\u2026<\/p>\n

get\u306e\u30c7\u30d5\u30a9\u30eb\u30c8\u5024\u3092\u6307\u5b9a\u3059\u308b<\/h3>\n

ObjectLike \u304c\u9593\u63a5\u7684\u306b\u547c\u3073\u51fa\u3057\u3066\u3044\u308b dict.get \u3067\u3059\u304c\u3001\u30c7\u30d5\u30a9\u30eb\u30c8\u5024\u304c\u6307\u5b9a\u3055\u308c\u3066\u3044\u306a\u3044\u306e\u3067 None \u304c\u8fd4\u3063\u3066\u3044\u307e\u3059\u3002\u3053\u308c\u3092\u7a7a\u306eObjectLike\u3092\u8fd4\u3059\u3088\u3046\u306b\u3057\u3066\u307f\u307e\u3059\u3002<\/p>\n

import json\n\nclass ObjectLike(dict):\n    def __getattr__(self, attr_name):\n        return self.get(attr_name, ObjectLike())\n\n# home\u304c\u306a\u304f\u306a\u3063\u3066\u3057\u307e\u3063\u305f\njson_data = \"\"\"{\n    \"name\": \"taro\",\n    \"age\": 20\n}\"\"\"\n\nuser = json.loads(json_data, object_hook=ObjectLike)\n\nprint(user.home.city)  # {}<\/code><\/pre>\n

AttributeError \u306f\u8d77\u304d\u306a\u304f\u306a\u308a\u307e\u3057\u305f\u304c None \u306f\u8fd4\u3063\u3066\u304d\u307e\u305b\u3093\u3002<\/p>\n

try\/except \u3067\u56f2\u3080<\/h3>\n

\u611a\u76f4\u306b\u3084\u308b\u306e\u304c\u4e00\u756a\uff01\uff1f\u3068\u3082\u601d\u3044\u307e\u3059\u304c\u3001\u30a2\u30af\u30bb\u30b9\u3059\u308b\u305f\u3073\u306b try\/except \u3067\u56f2\u3080\u306e\u306f\u3061\u3087\u3063\u3068\u3081\u3093\u3069\u304f\u3055\u3044\u3067\u3059\u306d\u3002<\/p>\n

import json\n\nclass ObjectLike(dict):\n    __getattr__ = dict.get\n\n# home\u304c\u306a\u304f\u306a\u3063\u3066\u3057\u307e\u3063\u305f\njson_data = \"\"\"{\n    \"name\": \"taro\",\n    \"age\": 20\n}\"\"\"\n\nuser = json.loads(json_data, object_hook=ObjectLike)\ntry:\n    city = user.home.city\nexcept AttributeError:\n    city = None\n\nprint(city)  # None<\/code><\/pre>\n

try\/except \u3067\u56f2\u3080 2<\/h3>\n

\u9014\u4e2d\u306e\u5c5e\u6027\u304c\u306a\u3044\u306e\u3067\u30a8\u30e9\u30fc\u306b\u306a\u308b\u3068\u3044\u3046\u306e\u306f\u69cb\u9020\u304c\u60f3\u5b9a\u3057\u305f\u3082\u306e\u3068\u7570\u306a\u308b\u72b6\u6cc1\u306a\u306e\u3067\u305d\u306e\u307e\u307e\u30a8\u30e9\u30fc\u3068\u3057\u3066\u6271\u3048\u305f\u65b9\u304c\u826f\u3044\u3067\u3057\u3087\u3046\u3002<\/p>\n

\u307e\u305fdict.get\u306e\u30c7\u30d5\u30a9\u30eb\u30c8\u5024\u306fNone\u306e\u307e\u307e\u3068\u3057\u3066 or \u3092\u4f7f\u3063\u305f\u30c7\u30d5\u30a9\u30eb\u30c8\u5024\u3092\u6307\u5b9a\u3057\u3066\u307f\u307e\u3059\u3002<\/p>\n

import json\n\nclass ObjectLike(dict):\n    __getattr__ = dict.get\n\n# home\u304c\u306a\u304f\u306a\u3063\u3066\u3057\u307e\u3063\u305f\njson_data = \"\"\"{\n    \"name\": \"taro\",\n    \"age\": 20\n}\"\"\"\n\nuser = json.loads(json_data, object_hook=ObjectLike)\ntry:\n    # try \u306e\u4e2d\u3067\u5fc5\u8981\u306a\u30c7\u30fc\u30bf\u3092\u53d6\u308b\u3088\u3046\u306b\u3059\u308b\n    age = user.age or -1        # age\u304cNone\u306a\u3069\u306e\u5834\u5408\u306e\u30c7\u30d5\u30a9\u30eb\u30c8\u5024\n    city = user.home.city or \"\" # city\u304cNone\u306a\u3069\u306e\u5834\u5408\u306e\u30c7\u30d5\u30a9\u30eb\u30c8\u5024\nexcept AttributeError:\n    # \u4f55\u3089\u304b\u306e\u4f8b\u5916\u51e6\u7406\u3001\u3053\u3053\u3067\u306f\u7d42\u4e86\u3059\u308b\n    print(\"\u60f3\u5b9a\u5916\u306e\u30c7\u30fc\u30bf\")\n    exit(1)\n\nprint(city)  # \u3053\u3053\u306b\u306f\u5230\u9054\u3057\u307e\u305b\u3093<\/code><\/pre>\n

Optional Chaining\u304c\u3067\u304d\u308b\u3068\u826f\u3044\u3093\u3060\u3051\u3069\u306a\u30fc\u3002<\/p>\n

\u8ab2\u984c\uff1adict\u306e\u5c5e\u6027\u3068\u304b\u3076\u308bJSON\u306e\u30ad\u30fc\u306f\u5229\u7528\u3067\u304d\u306a\u3044<\/h2>\n

__getattr__ \u306f\u5c5e\u6027\u304c\u306a\u3044\u5834\u5408\u306b\u5b9f\u884c\u3055\u308c\u308b\u306e\u3067\u3001dict\u306b\u5b58\u5728\u3059\u308b\u5c5e\u6027\u306f\u305d\u306e\u307e\u307e\u5229\u7528\u3067\u304d\u307e\u3059\u3002\u306a\u306e\u3067\u3001\u540d\u524d\u304c\u304b\u3076\u308b\u3068JSON\u306e\u30c7\u30fc\u30bf\u304c\u5229\u7528\u3067\u304d\u306a\u304f\u306a\u308a\u307e\u3059\u3002<\/p>\n

import json\n\nclass ObjectLike(dict):\n    __getattr__ = dict.get\n\njson_data = \"\"\"{\n    \"name\": \"taro\",\n    \"age\": 20,\n    \"values\": [1,2,3,4,5]\n}\"\"\"\n\nuser = json.loads(json_data, object_hook=ObjectLike)\n\nprint(user.values)    # \nprint(user.values())  # dict_values(['taro', 20, [1, 2, 3, 4, 5]])<\/code><\/pre>\n

\u4f8b\u3048\u3070 values \u3068\u3044\u3046\u306e\u306f\u8f9e\u66f8\u306e\u5024\u3060\u3051\u3092\u53d6\u5f97\u3059\u308b\u30e1\u30bd\u30c3\u30c9\u3067\u3059\u3002\u540d\u524d\u304c\u304b\u3076\u308b\u306e\u3067 user.values \u306f\u914d\u5217\u3067\u306f\u306a\u304f\u30e1\u30bd\u30c3\u30c9\u305d\u306e\u3082\u306e\u304c\u53d6\u5f97\u3067\u304d\u307e\u3059\u3002\u5b9f\u884c\u3059\u308b\u3068\u914d\u5217\u304c\u53d6\u5f97\u3067\u304d\u307e\u3059\u304c\u3001\u8f9e\u66f8\u5168\u4f53\u306e\u5024\u306e\u914d\u5217\u3067\u3059\u3002\u3053\u3053\u3067\u306f[1,2,3,4,5] \u304c\u6b32\u3057\u3044\u306e\u3067\u3001\u610f\u56f3\u3057\u306a\u3044\u52d5\u4f5c\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n

\u307e\u3068\u3081<\/h2>\n

\u5b9f\u969b\u306e\u3068\u3053\u308dpython-box<\/a>\u3068\u3044\u3063\u305f\u30e9\u30a4\u30d6\u30e9\u30ea\u3082\u3042\u308b\u306e\u3067\u3001\u305d\u3061\u3089\u3092\u5229\u7528\u3057\u305f\u65b9\u304c\u826f\u3044\u3068\u601d\u3044\u307e\u3059\u304c\u3001\u3068\u308a\u3042\u3048\u305aObjectLike\u306e\u4ed5\u7d44\u307f\u3067JSON\u306e\u30c7\u30fc\u30bf\u304c\u305d\u3053\u305d\u3053\u826f\u3044\u611f\u3058\u306b\u6271\u3048\u308b\u306e\u304c\u78ba\u8a8d\u3067\u304d\u307e\u3057\u305f\u3002<\/p>\n

\u307e\u305f Python3.8 \u304b\u3089\u306f TypedDict \u3068\u3044\u3046Type Hinting\u306e\u305f\u3081\u306e\u65b0\u3057\u3044\u578b\u304c\u5c0e\u5165\u3055\u308c\u3066\u3044\u308b\u306e\u3067\u3001\u305d\u308c\u3092\u6d3b\u7528\u3059\u308b\u65b9\u6cd5\u3082\u3042\u308a\u305d\u3046\u3067\u3059\u3002<\/p>\n

\u3042\u3068\u3001Go\u3067\u4f7f\u3048\u308b Golang: Convert JSON to Struct<\/a> \u306ePython\u7248\u304c\u6b32\u3057\u304b\u3063\u305f\u306e\u3067\u3059\u304c\u3001\u898b\u5f53\u305f\u3089\u306a\u304b\u3063\u305f\u306e\u3067\u3057\u305f\u3002<\/p>\n

\u304a\u308f\u308a<\/p>\n","protected":false},"excerpt":{"rendered":"

\u3053\u308c\u306f TECHSCORE Advent Calendar 2019 \u306e16\u65e5\u76ee\u306e\u8a18\u4e8b\u3067\u3059\u3002<\/p>\n

Python\u3067JSON\u30c7\u30fc\u30bf\u3092\u6271\u3046<\/p>\n

\u6700\u8fd1\u3067\u306f\u30de\u30a4\u30af\u30ed\u30b5\u30fc\u30d3\u30b9\u3060\u306a\u3093\u3060\u3068\u3001\u5916\u90e8\u30b5\u30fc\u30d3\u30b9\u306eHTTP\u306eAPI\u3092\u547c\u3073\u51fa\u3057\u3001JSON\u30c7\u30fc\u30bf\u3092\u6271\u3046\u6a5f\u4f1a\u306f\u5c11\u306a\u304f\u306a\u3044\u3068\u601d\u3044\u307e\u3059\u3002
\u7d9a\u304d\u3092\u8aad\u3080...<\/a><\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[332,317,18],"tags":[141,120],"_links":{"self":[{"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/posts\/24844"}],"collection":[{"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/comments?post=24844"}],"version-history":[{"count":21,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/posts\/24844\/revisions"}],"predecessor-version":[{"id":24963,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/posts\/24844\/revisions\/24963"}],"wp:attachment":[{"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/media?parent=24844"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/categories?post=24844"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/tags?post=24844"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}