Skip to content

Instantly share code, notes, and snippets.

@seozed
Last active May 11, 2020 06:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seozed/1fa306647e379f6ebd16cb40cecde663 to your computer and use it in GitHub Desktop.
Save seozed/1fa306647e379f6ebd16cb40cecde663 to your computer and use it in GitHub Desktop.
[jsonpath] 优化提取方法 #jsonpath
from jsonpath import jsonpath as _jsonpath
def jsonpath(obj, expr):
"""
优先项:如果匹配到的结果只有一个,则直接pop出该结果
"""
result = _jsonpath(obj, expr)
if isinstance(result, list) and len(result) == 1:
return result.pop()
return result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment