Q:

load json

import json

with open('data.txt') as json_file:
    data = json.load(json_file)
0
# Python program to read 
# json file 
   
   
import json 
   
# Opening JSON file 
f = open('data.json',) 
   
# returns JSON object as  
# a dictionary 
data = json.load(f) 
   
# Iterating through the json 
# list 
for i in data['emp_details']: 
    print(i) 
   
# Closing file 
f.close() 
2

import json

with open('path_to_file/person.json') as f:
  data = json.load(f)
1
//using JQuery
$.getJSON("test.json", function(json) {
    console.log(json); // this will show the info it in firebug console
});
2
# https://medium.com/@galea/how-to-love-jsonl-using-json-line-format-in-your-workflow-b6884f65175b
import json

def dump_jsonl(data, output_path, append=False):
    """
    Write list of objects to a JSON lines file.
    """
    mode = 'a+' if append else 'w'
    with open(output_path, mode, encoding='utf-8') as f:
        for line in data:
            json_record = json.dumps(line, ensure_ascii=False)
            f.write(json_record + '\n')
    print('Wrote {} records to {}'.format(len(data), output_path))

def load_jsonl(input_path) -> list:
    """
    Read list of objects from a JSON lines file.
    """
    data = []
    with open(input_path, 'r', encoding='utf-8') as f:
        for line in f:
            data.append(json.loads(line.rstrip('\n|\r')))
    print('Loaded {} records from {}'.format(len(data), input_path))
    return data
0

import json

with open('path_to_file/person.json') as f:
  data = json.load(f)

# Output: {'name': 'Bob', 'languages': ['English', 'Fench']}
print(data)
0

New to Communities?

Join the community