user1424739
user1424739

Reputation: 13683

unescape backslash in jq output

https://pubchem.ncbi.nlm.nih.gov/rest/pug/compound/cid/5317139/property/IsomericSMILES/JSON

For the above JSON, the following jq prints 5317139 CCC/C=C\\1/C2=C(C3C(O3)CC2)C(=O)O1.

.PropertyTable.Properties
| .[]
| [.CID, .IsomericSMILES]
| @tsv

But there are two \ before the first 1. Is it wrong, should three be just one \? How to get the correct number of backslash?

Upvotes: 1

Views: 950

Answers (1)

peak
peak

Reputation: 116790

The extra backslash in the output is the result of the request to produce TSV, since "\" has a special role to play in jq's TSV (e.g. "\t" signifies the tab character).

By contrast, consider:

jq -r '
  .PropertyTable.Properties
  | .[]
  | [.CID, .IsomericSMILES]
  | join("\t")' smiles.json
5317139 CCC/C=C\1/C2=C(C3C(O3)CC2)C(=O)O1

Upvotes: 1

Related Questions