function in jsngram.json2 module

Description

Append an object to a existing json file. The file should not have any end brackets and this function doesn't put an end bracket by default. It appends without looking it to get performance instead of flexibility. Creates new file with starting bracket, when the file is not exist.

Call json_end in this module when you finish the json file.

Example
jsngram.json2.json_append('/scratch/a.json', 1)
jsngram.json2.json_append('/scratch/a.json', 2)
jsngram.json2.json_append('/scratch/a.json', [3,4], list=True)
jsngram.json2.json_append('/scratch/a.json', 5)
jsngram.json2.json_end('/scratch/a.json')
# [1,2,3,4,5]

jsngram.json2.json_append('/tmp/out.json', ['a',0])
jsngram.json2.json_append('/tmp/out.json', ['b',1])
jsngram.json2.json_append('/tmp/out.json', ['c',2])
jsngram.json2.json_end('/tmp/out.json')

"""
[
 ['a',0]
,['b',1]
,['c',2]
]
"""
      
Usage

jsngram.json2.json_append(file_name, x, list=False, end=False)

Argument file_name must be a full path to a json file. The x is object that want to append to the json file. Set list = True, if the x is an array and want to add the elements of array instead of array itself. Set end = True, if you want to add an end bracket to close the json file immediately.