hash:da7dee6d1d9374b726e77e6aa321141cd22d679dc3d40ffdbb3cbfc
1. 安置
官网:https://stedolan.github.io/jq/download/
根基就是brew install、apt install、yum install之类的,,很简单
直接请求,格局明显不易读
$ curl -s https://horizon.stellar.org/transactions?limit=1&order=desc {"_links":{"next":{"href":"https://horizon.stellar.org/transactions?cursor=120624397026840576&limit=1&order=desc"},"prev":{"href":"https://horizon.stellar.org/transactions?cursor=120624397026840576&limit=1&order=asc"}},"_embedded":{"records":[{"memo":"MmFiOTViOTFmNzQ0MmUwY2EzY2I4NTIzZDIwYzFmNWE=","id":"da7dee6d1d9374b726e77e6aa321141cd22d679dc3d40ffdbb3cbfcbae93bd3e","paging_token":"120624397026840576","successful":true,"hash":"da7dee6d1d9374b726e77e6aa321141cd22d679dc3d40ffdbb3cbfcbae93bd3e","ledger":28085056,"created_at":"2020-02-05T13:01:24Z","source_account_sequence":"112094093760491433","fee_paid":100,"fee_charged":100,"max_fee":100,"operation_count":1,"result_xdr":"AAAAAAAAAGQAAAAAAAAAAQAAAAAAAAABAAAAAAAAAAA=","memo_type":"hash","valid_after":"1970-01-01T00:00:00Z"}]}}使用jq格局化
$ curl -s https://horizon.stellar.org/transactions?limit=1&order=desc | jq { "_links":{ "next":{ "href":"https://horizon.stellar.org/transactions?cursor=120624397026840576&limit=1&order=desc" }, "prev":{ "href":"https://horizon.stellar.org/transactions?cursor=120624397026840576&limit=1&order=asc" } }, "_embedded":{ "records":[ { "memo":"MmFiOTViOTFmNzQ0MmUwY2EzY2I4NTIzZDIwYzFmNWE=", "id":"da7dee6d1d9374b726e77e6aa321141cd22d679dc3d40ffdbb3cbfcbae93bd3e", "paging_token":"120624397026840576", "successful":true, "hash":"da7dee6d1d9374b726e77e6aa321141cd22d679dc3d40ffdbb3cbfcbae93bd3e", "ledger":28085056, "created_at":"2020-02-05T13:01:24Z", "source_account_sequence":"112094093760491433", "fee_paid":100, "fee_charged":100, "max_fee":100, "operation_count":1, "result_xdr":"AAAAAAAAAGQAAAAAAAAAAQAAAAAAAAABAAAAAAAAAAA=", "memo_type":"hash", "valid_after":"1970-01-01T00:00:00Z" } ] } } 2.2 取指定字段的值直接输入字段,使用.嵌套访谒,例如要获取records
$ curl -s https://horizon.stellar.org/transactions?limit=1&order=desc | jq ._embedded.records [ { "memo":"MmFiOTViOTFmNzQ0MmUwY2EzY2I4NTIzZDIwYzFmNWE=", "id":"da7dee6d1d9374b726e77e6aa321141cd22d679dc3d40ffdbb3cbfcbae93bd3e", "paging_token":"120624397026840576", "successful":true, "hash":"da7dee6d1d9374b726e77e6aa321141cd22d679dc3d40ffdbb3cbfcbae93bd3e", "ledger":28085056, "created_at":"2020-02-05T13:01:24Z", "source_account_sequence":"112094093760491433", "fee_paid":100, "fee_charged":100, "max_fee":100, "operation_count":1, "result_xdr":"AAAAAAAAAGQAAAAAAAAAAQAAAAAAAAABAAAAAAAAAAA=", "memo_type":"hash", "valid_after":"1970-01-01T00:00:00Z" } ] 2.3 过滤指定字段使用一个json指定所有字段,如{memo, hash},获取昨天的最高温度如下
$ curl -s https://horizon.stellar.org/transactions?limit=1&order=desc | jq ._embedded.records | jq ".[0]" | jq "{memo, hash}" { "memo":"MmFiOTViOTFmNzQ0MmUwY2EzY2I4NTIzZDIwYzFmNWE=", "hash":"da7dee6d1d9374b726e77e6aa321141cd22d679dc3d40ffdbb3cbfcbae93bd3e" } 2.4 获取多个字段的值使用逗号获取多个
$ curl -s https://horizon.stellar.org/transactions?limit=1&order=desc | jq "._embedded.records[0]" | jq ".memo, .hash" "AaUJ0NXa2UE1j4QiOfgy5qqhD8oT8kWI9Cy4xfvb/u8=" "fc3e37d08c99496468f03adbb01f0c32b614f2423508489456c5a32157622036" 2.5 筛选数组直接指定数组的索引即可
$ curl -s https://horizon.stellar.org/transactions?limit=1&order=desc| jq "._embedded.records" | jq ".[0, 9]" { "memo":"MmFiOTViOTFmNzQ0MmUwY2EzY2I4NTIzZDIwYzFmNWE=", "id":"da7dee6d1d9374b726e77e6aa321141cd22d679dc3d40ffdbb3cbfcbae93bd3e", "paging_token":"120624397026840576", "successful":true, "hash":"da7dee6d1d9374b726e77e6aa321141cd22d679dc3d40ffdbb3cbfcbae93bd3e", "ledger":28085056, "created_at":"2020-02-05T13:01:24Z", "source_account_sequence":"112094093760491433", "fee_paid":100, "fee_charged":100, "max_fee":100, "operation_count":1, "result_xdr":"AAAAAAAAAGQAAAAAAAAAAQAAAAAAAAABAAAAAAAAAAA=", "memo_type":"hash", "valid_after":"1970-01-01T00:00:00Z" } ... 3. 参考Curl 与jq 倡议json请求
标签:
原文地点:https://www.cnblogs.com/yueyun00/p/12267063.html
温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/web/30486.html