MCPcopy Create free account
hub / github.com/EntilZha/PyFunctional / json

Method json

functional/streams.py:212–244  ·  view source on GitHub ↗

Reads and parses the input of a json file handler or file. Json files are parsed differently depending on if the root is a dictionary or an array. 1) If the json's root is a dictionary, these are parsed into a sequence of (Key, Value) pairs 2) If the json'

(self, json_file)

Source from the content-addressed store, hash-verified

210 return self(input_file).map(jsonapi.loads).cache(delete_lineage=True)
211
212 def json(self, json_file):
213 """
214 Reads and parses the input of a json file handler or file.
215
216 Json files are parsed differently depending on if the root is a dictionary or an array.
217
218 1) If the json's root is a dictionary, these are parsed into a sequence of (Key, Value)
219 pairs
220
221 2) If the json's root is an array, these are parsed into a sequence
222 of entries
223
224 >>> seq.json('examples/users.json').first()
225 [u'sarah', {u'date_created': u'08/08', u'news_email': True, u'email': u'sarah@gmail.com'}]
226
227 :param json_file: path or file containing json content
228 :return: Sequence wrapping jsonl file
229 """
230 if isinstance(json_file, str):
231 file_open = get_read_function(json_file, self.disable_compression)
232 input_file = file_open(json_file)
233 json_input = jsonapi.load(input_file)
234 elif hasattr(json_file, "read"):
235 json_input = jsonapi.load(json_file)
236 else:
237 raise ValueError(
238 "json_file must be a file path or implement the iterator interface"
239 )
240
241 if isinstance(json_input, list):
242 return self(json_input)
243 else:
244 return self(json_input.items())
245
246 # pylint: disable=keyword-arg-before-vararg
247 def sqlite3(self, conn, sql, parameters=None, *args, **kwargs):

Callers 6

test_jsonMethod · 0.80
test_gzip_jsonMethod · 0.80
test_bz2_jsonMethod · 0.80
test_xz_jsonMethod · 0.80
test_to_jsonMethod · 0.80

Calls 1

get_read_functionFunction · 0.90

Tested by 6

test_jsonMethod · 0.64
test_gzip_jsonMethod · 0.64
test_bz2_jsonMethod · 0.64
test_xz_jsonMethod · 0.64
test_to_jsonMethod · 0.64