score:3

"It's only outputting one entry" because you only select the first dictionary in the JSON file when you say raw_data2 = raw_data[0]

Try something like this as a starting point (I haven't tested/ran it):

import json

def run():
    with open('data/bricsinvestorsfirst.json') as input_file:
        raw_data = json.load(input_file)

    children = []
    for item in raw_data:
        children.append({
            'name': item['name'],
            'size': '500'
        })

    container = {}
    container['name'] = 'name'
    container['children'] = children

    return json.dumps(container)

if __name__ == '__main__':
    print run()

score:12

Try this. Though your sample input and output data don't really give many clues as to where the "name" fields should come from. I've assumed you wanted the name of the original item in your list.

original_json = json.load(open('data/bricsinvestorsfirst.json'),'r')

response_json = {}
response_json["name"] = "analytics"

# where your children list will go
children = []

size = 500 # or whatever else you want

# For each item in your original list
for item in original_json:
    children.append({"name" : item["name"],
                     "size" : size})

response_json["children"] = children

print json.dumps(response_json,indent=2)

Related Query

More Query from same tag