MCPcopy Create free account
hub / github.com/simplejson/simplejson / JSONArray

Function JSONArray

simplejson/decoder.py:246–290  ·  view source on GitHub ↗
(state, scan_once, array_hook=None,
              _w=WHITESPACE.match, _ws=WHITESPACE_STR)

Source from the content-addressed store, hash-verified

244 return pairs, end
245
246def JSONArray(state, scan_once, array_hook=None,
247 _w=WHITESPACE.match, _ws=WHITESPACE_STR):
248 (s, end) = state
249 values = []
250 nextchar = s[end:end + 1]
251 if nextchar in _ws:
252 end = _w(s, end + 1).end()
253 nextchar = s[end:end + 1]
254 # Look-ahead for trivial empty array
255 if nextchar == ']':
256 if array_hook is not None:
257 values = array_hook(values)
258 return values, end + 1
259 elif nextchar == '':
260 raise JSONDecodeError("Expecting value or ']'", s, end)
261 _append = values.append
262 while True:
263 value, end = scan_once(s, end)
264 _append(value)
265 nextchar = s[end:end + 1]
266 if nextchar in _ws:
267 end = _w(s, end + 1).end()
268 nextchar = s[end:end + 1]
269 end += 1
270 if nextchar == ']':
271 break
272 elif nextchar != ',':
273 raise JSONDecodeError("Expecting ',' delimiter or ']'", s, end - 1)
274
275 try:
276 if s[end] in _ws:
277 end += 1
278 if s[end] in _ws:
279 end = _w(s, end + 1).end()
280 except IndexError:
281 pass
282
283 if s[end:end + 1] == ']':
284 raise JSONDecodeError(
285 "Illegal trailing comma before end of array",
286 s, end - 1)
287
288 if array_hook is not None:
289 values = array_hook(values)
290 return values, end
291
292class JSONDecoder(object):
293 """Simple JSON <http://json.org> decoder

Callers

nothing calls this directly

Calls 2

JSONDecodeErrorClass · 0.85
scan_onceFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…