zoukankan      html  css  js  c++  java
  • jsonpath_rw操作json

    from jsonpath_rw import parse
    
    def get_key_from_data(key,data):
        # 定义匹配规则
        json_expr=parse(key)
        result=json_expr.find(data)
        # [match.value for match in male][0]
        return [match.value for match in result]
    
    if __name__ == '__main__':
        # key="msg"
        # key="data[*].uid"
        key="$..uid"
        data={"code":"00","msg":"success","data":[
            {"uid":"1","name":"zs","age":11},
            {"uid": "2", "name": "ls", "age": 12},
            {"uid": "3", "name": "ww", "age": 13}
        ]}
        print(get_key_from_data(key,data))
  • 相关阅读:
    openresty
    ATS 相关
    pandas
    flask
    ansible
    zipline
    bcolz
    数据分析 --- concat
    Go --- 基础使用
    Go --- 基础介绍
  • 原文地址:https://www.cnblogs.com/reyinever/p/11282822.html
Copyright © 2011-2022 走看看