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

Support resolving arrays in query string and body #197

Open
eamodio opened this issue Apr 23, 2018 · 8 comments
Open

Support resolving arrays in query string and body #197

eamodio opened this issue Apr 23, 2018 · 8 comments

Comments

@eamodio
Copy link

eamodio commented Apr 23, 2018

  • VSCode Version: 1.23
  • OS Version: Windows 10
  • REST Client Version: 0.18.2

I would really like the ability to use a jsonpath query that resolves to an array in both the query string and request body.

Here is an example:

# @name data
POST http://httpbin.org/post
Content-Type: application/json

{
    "teams": [
        {
            "id": "1",
            "name": "Team 1"
        },
        {
            "id": "2",
            "name": "Team 2"
        },
        {
            "id": "3",
            "name": "Team 3"
        }
    ]
}

###

# Resolves to http://httpbin.org/get?ids=1
# Want it to resolve to http://httpbin.org/get?ids=1,2,3 

GET http://httpbin.org/get?ids={{data.response.body.$.json.teams[*].id}}
Content-Type: application/json

###

# Resolves to { "ids": "1" }
# Want it to resolve to { "ids": [1,2,3] }

POST http://httpbin.org/post
Content-Type: application/json

{
    "ids": "{{data.response.body.$.json.teams[*].id}}"
}

Awesome extension BTW!

@Huachao
Copy link
Owner

Huachao commented Apr 23, 2018

@eamodio nice suggestion, interesting idea.

@eamodio
Copy link
Author

eamodio commented Apr 23, 2018

Thanks -- fyi, it seems somewhat like a bug right now that a jsonpath query like {{data.response.body.$.json.teams[*].id}} is currently equivalent to {{data.response.body.$.json.teams[0].id}}

@Huachao
Copy link
Owner

Huachao commented Apr 23, 2018

@eamodio actually it's by design

const result = jp.query(body, path);
const value = typeof result[0] === 'string' ? result[0] : JSON.stringify(result[0]);

@niusounds
Copy link

is there any plan to support this feature?

@Huachao
Copy link
Owner

Huachao commented Jul 9, 2020

@niusounds I am still planing this since I met a problem. What's the string representation(serialization) of the array result, simply JSON stringify the array or something else?

@rodrigoestevao
Copy link

rodrigoestevao commented Aug 27, 2020

@Huachao, I do have the same need. I was taking a look on this link and I do believe that a JSON stringify with the correct replacer, would do the job for most cases. Please, take a look and see what do you think about it.

Cheers

@fskroes
Copy link

fskroes commented Sep 26, 2020

I would love to have this as well 👍

@gertjvr-jb
Copy link

This would be an awesome addition please merge #853

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

No branches or pull requests

6 participants