def json_text():
"""Returns the parser for Json formatted data"""
# Taken from https://github.com/vlasovskikh/funcparserlib/blob/master/funcparserlib/tests/json.py
# and modified slightly
unwrap = lambda x: x.value
null = (n('null') | n('Null')) >> const(None) >> unwrap
value = forward_decl()
member = (string >> unwrap) + op_(u':') + value >> tuple
object = (
op_(u'{') +
maybe(member + many(op_(u',') + member) + maybe(op_(','))) +
op_(u'}')
>> make_object)
array = (
op_(u'[') +
maybe(value + many(op_(u',') + value) + maybe(op_(','))) +
op_(u']')
>> make_array)
value.define(
null
| (true >> unwrap)
| (false >> unwrap)
| object
| array
| (number >> unwrap)
| (string >> unwrap))
json_text = object | array
return json_text
评论列表
文章目录