Advertisement
sdjakhfska

Untitled

Sep 29th, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.38 KB | None | 0 0
  1. import json
  2. unflatten_json = """
  3. {
  4.  "type": "array",
  5.  "items": {
  6.    "type": "object",
  7.    "properties": {
  8.      "active": {
  9.        "type": "boolean"
  10.      },
  11.      "displayOrder": {
  12.        "type": "integer"
  13.      },
  14.      "label": {
  15.        "type": "string"
  16.      },
  17.      "pipelineId": {
  18.        "type": "string"
  19.      },
  20.      "stages": {
  21.        "type": "array",
  22.        "items": {
  23.          "type": "object",
  24.          "properties": {
  25.            "active": {
  26.              "type": "boolean"
  27.            },
  28.            "closedWon": {
  29.              "type": "boolean"
  30.            },
  31.            "displayOrder": {
  32.              "type": "integer"
  33.            },
  34.            "label": {
  35.              "type": "string"
  36.            },
  37.            "probability": {
  38.              "type": "integer"
  39.            },
  40.            "stageId": {
  41.              "type": "string"
  42.            }
  43.          }
  44.        }
  45.      }
  46.    }
  47.  }
  48. }
  49. """
  50.  
  51. def flatten(dic):
  52.     flat = []
  53.     for k, v in dic.items():
  54.         if isinstance(v, dict):
  55.             flat += [(k + '.' + value[0], value[1]) for value in  flatten(v)]
  56.         else:
  57.             flat += [(k, v)]
  58.  
  59.     return flat
  60.  
  61. data = json.loads(unflatten_json)
  62. data = dict(flatten(data))
  63. #json is ready
  64. parent_object_you_want_to_apply = "SomethingISetToGoHere"
  65. data = {parent_object_you_want_to_apply:data}
  66. print(data)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement