Last active
May 11, 2020 06:19
-
-
Save seozed/1fa306647e379f6ebd16cb40cecde663 to your computer and use it in GitHub Desktop.
[jsonpath] 优化提取方法 #jsonpath
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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