2016-12-09 24 views
-1

出于某种原因,我不知道为什么,当我在jqplay上测试以下行的格式时,它看起来与我在命令行上运行它时看起来不同。jq是在我的JSON中重新排序密钥

My original data looks as such:

{"type":"user.list","users":[{"type":"user","id":"57db1b1b9jdjd84f99b977785ba","user_id":"janwjf3sqdditwn7c7","anonymous":false,"email":"[email protected]","phone":null,"name":"Joe Smith","pseudonym":null,"avatar":{"type":"avatar","image_url":null},"app_id":"b5vkddxvop","companies":{"type":"company.list","companies":[]},"location_data":{"type":"location_data","city_name":"Murfreesboro","continent_code":"NA","country_name":"United States","latitude":35.8896,"longitude":-86.3166,"postal_code":"37130","region_name":"Tennessee","timezone":"America/Chicago","country_code":"USA"},"last_request_at":1478624249,"last_seen_ip":"69.139.122.123","created_at":1473977115,"remote_created_at":1466313380,"signed_up_at":1466313380,"updated_at":1480970142,"session_count":1,"social_profiles":{"type":"social_profile.list","social_profiles":[]},"unsubscribed_from_emails":false,"user_agent_data":"Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko","tags":{"type":"tag.list","tags":[{"type":"tag","id":"587061","name":"Mixpanel Import - 2016-09-15 21:25:08 UTC"}]},"segments":{"type":"segment.list","segments":[{"type":"segment","id":"581a048c4ad88d6b458198d7"},{"type":"segment","id":"5845cd57c91b1fe3e440032b"},{"type":"segment","id":"5845cab9d951b43e7d33d2f7"}]},"custom_attributes":{"mixpanel_id":"1556710d919339-0beb72f2966b408-69581467-cff8c-1556710d91a54b","claimCount":"2","memberType":"claimant"}}],"scroll_param":"56386a4d-743b-470a-ae9f-848b991e0ccc"} 

如果您转储到jq playground,它格式化它究竟应该如何,我怎么想的那样,which looks like this

{"type":"user","id":"57db1b1b9jdjd84f99b977785ba","user_id":"janwjf3sqdditwn7c7","anonymous":false,"email":"[email protected]","phone":null,"name":"Joe Smith","pseudonym":null,"avatar":{"type":"avatar","image_url":null},"app_id":"b5vkddxvop","companies":{"type":"company.list","companies":[]},"location_data":{"type":"location_data","city_name":"Murfreesboro","continent_code":"NA","country_name":"United States","latitude":35.8896,"longitude":-86.3166,"postal_code":"37130","region_name":"Tennessee","timezone":"America/Chicago","country_code":"USA"},"last_request_at":1478624249,"last_seen_ip":"69.139.122.123","created_at":1473977115,"remote_created_at":1466313380,"signed_up_at":1466313380,"updated_at":1480970142,"session_count":1,"social_profiles":{"type":"social_profile.list","social_profiles":[]},"unsubscribed_from_emails":false,"user_agent_data":"Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko","tags":{"type":"tag.list","tags":[{"type":"tag","id":"587061","name":"Mixpanel Import - 2016-09-15 21:25:08 UTC"}]},"segments":{"type":"segment.list","segments":[{"type":"segment","id":"581a048c4ad88d6b458198d7"},{"type":"segment","id":"5845cd57c91b1fe3e440032b"},{"type":"segment","id":"5845cab9d951b43e7d33d2f7"}]},"custom_attributes":{"mixpanel_id":"1556710d919339-0beb72f2966b408-69581467-cff8c-1556710d91a54b","claimCount":"2","memberType":"claimant"}} 

这正是我多么希望数据进行重组。

转到链接jqplay,看看yourselft,只需输入到这个过滤器并单击紧凑输出:

.users[] 

但由于某些原因,当我在命令行中运行以下命令:

curl https://api.example.com/users/scroll -u 'dG9rOjg4YmUxMzr4XzJmNzZfNDkwY3934jU2X2mrM2MxZGEzYWI2MzoxOjA=': -H 'Accept:application/json'| jq -c '.users[]' 

It spits out a result that is totally not formmated how it is suppose to come out, despite using the exact same filter

{"custom_attributes":{"memberType":"claimant","claimCount":"2","mixpanel_id":"1556710d919339-0beb72f2966b408-69581467-cff8c-1556710d91a54b"},"segments":{"segments":[{"id":"581a048c4ad88d6b458198d7","type":"segment"},{"id":"5845cd57c91b1fe3e440032b","type":"segment"},{"id":"5845cab9d951b43e7d33d2f7","type":"segment"}],"type":"segment.list"},"tags":{"tags":[{"name":"Mixpanel Import - 2016-09-15 21:25:08 UTC","id":"587061","type":"tag"}],"type":"tag.list"},"user_agent_data":"Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko","unsubscribed_from_emails":false,"social_profiles":{"social_profiles":[],"type":"social_profile.list"},"session_count":1,"updated_at":1480970142,"signed_up_at":1466313380,"pseudonym":null,"name":"Joe Smith","phone":null,"email":"[email protected]","anonymous":false,"user_id":"janwjf3sqdditwn7c7","id":"57db1b1b9jdjd84f99b977785ba","type":"user","avatar":{"image_url":null,"type":"avatar"},"app_id":"b5vkddxvop","companies":{"companies":[],"type":"company.list"},"location_data":{"country_code":"USA","timezone":"America/Chicago","type":"location_data","city_name":"Murfreesboro","continent_code":"NA","country_name":"United States","latitude":35.8896,"longitude":-86.3166,"postal_code":"37130","region_name":"Tennessee"},"last_request_at":1478624249,"last_seen_ip":"69.139.122.123","created_at":1473977115,"remote_created_at":1466313380} 

正如你所知道的,与jqplayground功能中的结果无关。为了让事情变得更加令人困惑,其他人运行它并正确格式化。最重要的是,大约一周前,它对我来说工作得很好。

我也尝试删除jq并重新安装它没有成功。我在Ubuntu 14.04.2 LTS(GNU/Linux 3.13.0-51-generic x86_64)上运行它,如果这有帮助的话。

任何帮助将不胜感激!

+0

那么它有什么“错误”?它怎么没有格式化你如何预期它? –

+0

@Jeff - 这是一个键盘顺序问题。 – peak

+0

@ wizkids121 - 请指出您正在使用的jq版本。 – peak

回答

0

jq 1.3并不总是尊重JSON对象中的键的顺序。假设您使用jq 1.3(或更早版本),解决方案将升级到更高版本(1.4,1.5或“主”版本)。