我试图在linux中为替代json文件编写一个查询,并将其写入一个新文件中。
My json文件的格式如下:
{"intents": [
{
"patterns": "'For the last 8 years of his life, Galileo was under house arrest for espousing this man's theory'",
"responses": "Copernicus"
},
{
"patterns&
我想将bash中的关联数组转换为JSON散列/dict。我更愿意使用JQ来完成这个任务,因为它已经是一个依赖项,而且我可以依赖它来生成格式良好的json。有人能示范一下如何做到这一点吗?
#!/bin/bash
declare -A dict=()
dict["foo"]=1
dict["bar"]=2
dict["baz"]=3
for i in "${!dict[@]}"
do
echo "key : $i"
echo "value: ${dict[$i]}"
done