Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import json
- unflatten_json = """
- {
- "type": "array",
- "items": {
- "type": "object",
- "properties": {
- "active": {
- "type": "boolean"
- },
- "displayOrder": {
- "type": "integer"
- },
- "label": {
- "type": "string"
- },
- "pipelineId": {
- "type": "string"
- },
- "stages": {
- "type": "array",
- "items": {
- "type": "object",
- "properties": {
- "active": {
- "type": "boolean"
- },
- "closedWon": {
- "type": "boolean"
- },
- "displayOrder": {
- "type": "integer"
- },
- "label": {
- "type": "string"
- },
- "probability": {
- "type": "integer"
- },
- "stageId": {
- "type": "string"
- }
- }
- }
- }
- }
- }
- }
- """
- def flatten(dic):
- flat = []
- for k, v in dic.items():
- if isinstance(v, dict):
- flat += [(k + '.' + value[0], value[1]) for value in flatten(v)]
- else:
- flat += [(k, v)]
- return flat
- data = json.loads(unflatten_json)
- data = dict(flatten(data))
- #json is ready
- parent_object_you_want_to_apply = "SomethingISetToGoHere"
- data = {parent_object_you_want_to_apply:data}
- print(data)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement