-
Lets say I have text.txt file with UTF-8 text with tabs, control characters and so on. Q: what needs to be done to add/inject content content of that file as |
Beta Was this translation helpful? Give feedback.
Replies: 8 comments 4 replies
-
Use the
|
Beta Was this translation helpful? Give feedback.
-
If you only want to wrap the content of the file into jq -Rs '{ data: . }` Otherwise, if you want to use the content of that file to modify JSON values from another input, so you can't use |
Beta Was this translation helpful? Give feedback.
-
OK it works. |
Beta Was this translation helpful? Give feedback.
-
@kloczek Maybe you may want |
Beta Was this translation helpful? Give feedback.
-
Simple in the "data" content for example new lines are replaced by \n. I need to extract ant present that field with replaced all those quoted parts to print original text. |
Beta Was this translation helpful? Give feedback.
-
To inject the content of the text.txt file as a JSON field {"data": "multi line text"}, you'll need to follow these steps: Preprocess the Text File: Before using jq, you may need to pre-process the text.txt file to ensure it's properly formatted for conversion to JSON. Once the text file is cleaned up, you can use jq to convert it into a JSON object. cat text.txt | jq -R 'split("\n") | map({data: .})' This command reads the content of text.txt, splits it into lines, and creates an array of objects with the key data for each line. Inject the Content: If you want to inject this JSON content into an existing JSON structure, you'll need to merge it appropriately. This can be done using tools like jq or by writing a script in a programming language like Python. cat existing.json | jq --argjson newContent "$(cat text.json)" '. + $newContent' This command reads the content of existing.json, reads the content from the text file, and merges them together. Remember, the exact commands may vary depending on the specific content and structure of your text.txt file and the existing JSON data. Always make sure to back up your data before making any modifications. |
Beta Was this translation helpful? Give feedback.
-
So is it possible using jq to extract such long text filed to original text form? 🤔 |
Beta Was this translation helpful? Give feedback.
-
OK it works. Thank you 👍 |
Beta Was this translation helpful? Give feedback.
OK it works. Thank you 👍