Mozilla rest client post json object
Asked Answered
C

1

5

I am using Mozilla fire fox add-on RESTClient to test my web-services. Up to this I was using POST method by setting header Content-Type:application/x-www-form-urlencoded and data separated by & in request body e.g. id=1&title=abc

But now I want to POST the JSON object to using the same service. The sample objects are as below :

[
    {
         "id": 4
         "type":"alpha", 
         "title":"Title1"
    }
]

OR

[
    {
         "id": 4
         "type":"alpha", 
         "title":"Alpha"
    },
    {
         "id": 5
         "type":"beta", 
         "title":"Beta"
    },
    {
         "id": 6
         "type":"gama", 
         "title":"Gama"
    }
]

OR

[
    {
        "id": 5,
        "type":"beta", 
        "title":"Sample beta", 
        "children":[{
                "id": 6,
                "type":"betachild", 
                "title":"Beta child 1"
            },
            {
                "id": 7,
                "type":"betachild", 
                "title":"Beta child 2"
            },
            {
                "id": 8,
                "type":"betachild", 
                "title":"Beta child 3"
            }
        ]
    }
] 

OR

[
    {
        "id": 5,
        "type":"beta", 
        "title":"Sample beta", 
        "children":[{
                "id": 6,
                "type":"betachild", 
                "title":"Beta child 1"
            },
            {
                "id": 7,
                "type":"betachild", 
                "title":"Beta child 2"
            },
            {
                "id": 8,
                "type":"betachild", 
                "title":"Beta child 3"
            }
        ]
    }, 
    {
        "id": 9,
        "type":"beta", 
        "title":"Sample gama", 
        "children":[{
                "id": 10,
                "type":"gamachild", 
                "title":"Gama child 1"
            },
            {
                "id": 11,
                "type":"gamachild", 
                "title":"Gama child 2"
            },
            {
                "id": 12,
                "type":"gamachild", 
                "title":"Gama child 3"
            }
        ]
    }
] 

How can I pass such JSON object in POST request using RESTClient add-on?

Clomp answered 11/5, 2015 at 12:28 Comment(3)
Why do you set header Content-Type:application/x-www-form-urlencoded? Can't you set json/xml?Dextrose
@Dextrose Yes, I had set it and found it working OK. The only change I was required to do was set the header "Content-type:application/json".Clomp
Great! My typo as well. Just noticed. I wanted to mean application/json except json/xml. :)Dextrose
D
13

Set the content type as Content-type:application/json

Dextrose answered 14/8, 2015 at 13:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.