In [1]:
import json
import os
import codecs
import operator
arr = {}
for filename in os.listdir("./pages_json"):
    if filename.endswith(".json"):
        file = json.load(codecs.open('./pages_json/'+filename, 'r', 'utf-8'))
        sorted_file = dict(list(reversed(sorted(file.items(), key=lambda x: x[1])))) #sort by value
        for key in sorted_file:
            if key in arr:
                arr[key] += 1
            else:
                arr[key] = 1
# sorted_out = list(reversed(sorted(arr.items(), key=lambda x: x[1])))
with open('./feq_words.json', 'w', encoding='utf8') as json_file:
#     json.dump(sorted_out, json_file, ensure_ascii=False, sort_keys=True)
    json.dump(arr, json_file, ensure_ascii=False, sort_keys=True)
    json_file.close()

In [ ]: