jmespath / jmespath/jmespath.py

How to pass string with backslash at end to json_query

Open
#323 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
2.4k
Forks
212
PR merge metrics
No merged PRs in 30d

Description

Below is the JSON output text from a command, trying to fetch FullName and FileVersionRaw where FullName not contains '\msvc\\'

```
{
"windows_result.output": [
{
"FullName": "E:\\\\app\\\\client\\\\product\\\\client\\\\bin\\\\file.txt",
"Mode": "-a----",
"Target": [],
"VersionInfo": {
"FileVersionRaw": "19.0.0.0",
"ProductVersionRaw": "0.0.0.0"

}
},
{
"FullName": "E:\\\\app\\\\client\\\\product\\\\msvc\\\\vc10\\\\file.txt",
"Mode": "-a----",
"Target": [],
"VersionInfo": {
"FileVersionRaw": "19.0.0.0",
"ProductVersionRaw": "0.0.0.0"

}
}
]
}

```

Below code produces result as we search only for string '\\\msvc' which starts with backslash

```
- name: Print result - Windows
debug:
msg: "{{ windows_result.output | to_json | from_json | json_query(client_path) }}"
vars:
client_path: "[? !contains(FullName,'\\msvc')].{FullName: FullName, FileVersionRaw: VersionInfo.FileVersionRaw}"

```

Result output:

```
"msg": [
{
"FileVersionRaw": "19.0.0.0",
"FullName": "E:\\\\app\\\\client\\\\product\\\\client\\\\bin\\\\file.txt"
}
]

```

However if string modified to '\\\msvc\\\\' to search msvc between backslashes, \\' at end considered as escape for single quote and throws error. Please help.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.