Skip to content

Support transform value by regex #25

@takato1314

Description

@takato1314

Hi, i would like to transform the following source json:

{
  "friends": [
    {"name": "Chris", "url": "https://localhost/feature/logs?IncludeDetails=true&StartDate=2023-01-14&api_key=58fd29c2-af2d-4d60-80b1-e2f6fbba621d&format=json"}
  ]
}

So that i can map it to {apiKey: value} where the value is derived from the api_key query string. I tried to use something like this but to no avail.

.friends
  | map({
    name: .name, 
    apiKey: regex(.url, "[?&]api_key=([^&]+)")
  })

The output is:

[{"name": "Chris", "apiKey": true}]

which i understand it makes sense because the regex function only asserts whether the text provided matches the regex or not. However, what i need here is to extract the api_key and map it to a new value. Is this doable?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions