This utility is a Node.js script that converts JSON data to JSONL (JSON Lines) format. It also reads completion text from Microsoft Word documents and includes it in the final JSONL output.
- Converts JSON data to JSONL format
- Reads completion text from Word documents
- Handles newline characters in JSONL
-
Install Node.js on your computer.
-
Clone this repository or download the source code.
-
Open a terminal or command prompt, navigate to the directory containing the source code, and run:
npm install
This command installs the required dependencies: fs, mammoth.
- Prepare an input javascript file containing an array of objects. Each object should have the following structure:
module.exports = [{
"prompt": {
"question": "What is the capital?",
"additionalInfo": "This city serves as the state's administrative center."
},
"wordFile": "completion1.docx"
}]
- Save the input.js file in the same directory as the script and name it input.js.
- Update the inputJson variable in the script to require the input.js file:
const inputJson = require("./input");
- Run the script
node index.js
The script will generate a JSONL file named output.jsonl
in the same directory.
Suppose you have the following JSON input data in a file named input.js
:
module.exports = [
{
"prompt": {
"question": "What is the capital?",
"additionalInfo": "This city serves as the state's administrative center."
},
"wordFile": "completion1.docx"
},
{
"prompt": {
"question": "What is the state flower?",
"additionalInfo": "This flower is native to the Pacific Northwest."
},
"wordFile": "completion2.docx"
}
]
And you have two Word documents (completion1.docx
and completion2.docx
) containing the completion text.
When you run the script, it will generate a JSONL file (output.jsonl
) with the following content:
{"prompt":"{\"question\":\"What is the capital?\",\"additionalInfo\":\"This city serves as the state's administrative center.\"}\nAnswer:","completion":" The capital of Washington State is Olympia."}
{"prompt":"{\"question\":\"What is the state flower?\",\"additionalInfo\":\"This flower is native to the Pacific Northwest.\"}\nAnswer:","completion":" The state flower of Washington is the Coast Rhododendron."}