From a2b12f75ea6fb010dac6fbf6e5e539ad0e69a2f4 Mon Sep 17 00:00:00 2001 From: Alexander Nelzin Date: Thu, 13 Nov 2014 23:56:05 +0300 Subject: [PATCH] Fixed and added test for JSON properties order. --- httpie/input.py | 2 +- tests/test_httpie.py | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/httpie/input.py b/httpie/input.py index fc4967f1..19bdd904 100644 --- a/httpie/input.py +++ b/httpie/input.py @@ -640,7 +640,7 @@ def parse_items(items, if item.sep in SEP_GROUP_RAW_JSON_ITEMS: try: - value = json.loads(value) + value = json.loads(value, object_pairs_hook=OrderedDict) except ValueError as e: raise ParseError('"%s": %s' % (item.orig, e)) target = data diff --git a/tests/test_httpie.py b/tests/test_httpie.py index 2ee647ea..35150dcb 100644 --- a/tests/test_httpie.py +++ b/tests/test_httpie.py @@ -63,3 +63,8 @@ class TestHTTPie: assert HTTP_OK in r assert '"User-Agent": "HTTPie' in r, r assert '"Foo": "bar"' in r + + def test_json_order(self, httpbin): + r = http('PATCH', httpbin.url + '/patch', 'order:={"map":{"1":"first","2":"second"}}') + assert HTTP_OK in r + assert r.json['data'] == '{"order": {"map": {"1": "first", "2": "second"}}}'