Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to post arrays of anonymous JSON objects #121

Closed
chuma opened this issue Jan 10, 2013 · 3 comments
Closed

Ability to post arrays of anonymous JSON objects #121

chuma opened this issue Jan 10, 2013 · 3 comments

Comments

@chuma
Copy link

chuma commented Jan 10, 2013

Was trying to use httpie to post multiple events using the http://open.sen.se/ API. This accepts an array of unnamed objects in the form of:

[
    {
        "feed_id": 12345,
        "value": "foo"
    },
    {
        "feed_id":23456,
        "value": 2134
    },
    ...
]

Found that I could not seem to make httpie create JSON like this. Attempting to use the := separator for raw JSON without a key name created this output:

[victor@klamm ~]$ http -p B api.sen.se/events/  :='[{"feed_id": 24571, "value": 64.0}, {"feed_id":24572, "value":60.0}]'
{
    "": [
        {
            "feed_id": 24571, 
            "value": 64.0
        }, 
        {
            "feed_id": 24572, 
            "value": 60.0
        }
    ]
}
@jkbrzt
Copy link
Member

jkbrzt commented Jan 10, 2013

@chuma, this you can do by passing the raw JSON in via STDIN. For example:

echo '[{"feed_id": 24571, "value": 64.0}, {"feed_id":24572, "value":60.0}]' | http api.sen.se/events/ 

@jkbrzt jkbrzt closed this as completed Jan 11, 2013
@zhao-ji
Copy link

zhao-ji commented Mar 21, 2017

@jakubroztocil good job! you solve my problem

@evandro777
Copy link

@jakubroztocil, I am using the http 0.9.2 and it seens that it doesn't work that anymore.

I've created a test.php with the code:

<?php
print_r($_REQUEST);

Then i tried the requests below:

echo '[{"feed_id": 24571, "value": 64.0}, {"feed_id":24572, "value":60.0}]' | http http://localhost/CRMvTiger_Rodobens/test.php
Return:
Array
(
)

echo '[{"feed_id": 24571, "value": 64.0}, {"feed_id":24572, "value":60.0}]' | http --form http://localhost/CRMvTiger_Rodobens/test.php
Return:
Array
(
)

echo '[{"feed_id": 24571, "value": 64.0}, {"feed_id":24572, "value":60.0}]' | http --json http://localhost/CRMvTiger_Rodobens/test.php
Return:
Array
(
)

echo '{"feed_id": 24571, "value": 64.0}, {"feed_id":24572, "value":60.0}' | http http://localhost/CRMvTiger_Rodobens/test.php
Return:
Array
(
)

echo '{"feed_id": 24571, "value": 64.0}, {"feed_id":24572, "value":60.0}' | http --json http://localhost/CRMvTiger_Rodobens/test.php
Return:
Array
(
)

echo '{"feed_id": 24571, "value": 64.0}, {"feed_id":24572, "value":60.0}' | http --form http://localhost/CRMvTiger_Rodobens/test.php
Return:
Array
(
[{"feed_id":24571,"value":64_0},{"feed_id":24572,_"value":60_0}
] =>
)

The only which return something is the last one, but not was i was expecting, it returned all json as a key with an empty value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants