我可以将字符串变量传递给jq而不是文件吗? [英] Can I pass a string variable to jq not the file?

查看:115
本文介绍了我可以将字符串变量传递给jq而不是文件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将JSON字符串转换为bash中的数组. JSON字符串作为参数传递到bash脚本(文件中不存在).

I want to convert JSON string into an array in bash. The JSON string is passed to the bash script as an argument (it doesn't exist in a file).

有没有一种方法可以在不使用某些临时文件的情况下实现?

Is there a way of achieving it without using some temp files?

与此类似:

script.sh

#! /bin/bash
json_data='{"key":"value"}'
jq '.key' $json_data

jq: error: Could not open file {key:value}: No such file or directory

推荐答案

我建议使用bash

I would suggest using a bash here string. e.g.

jq '.key' <<< "$json_data"

这篇关于我可以将字符串变量传递给jq而不是文件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆