The JSON variable is parsed in the shell to obtain the value of value1 corresponding to key1, as follows:
s="{"key1":"abc","key2":"value2","key3":"value3"}"
parse_json(){
echo "${1//\"/}" | sed "s/.*$2:\([^,}]*\).*/\1/"
}
value=$(parse_json $s "key1")
echo $value
----------------------
output abc
Read More:
- Shell: How to Get System Current Tme and Format it
- Termux setting path environment variable
- [Solved] Sed Failed to Reference Variable error: extra characters after command
- [Solved] Ubuntu 20.04.3 Fail to Start sshd Error: Failed to start OpenBSD Secure Shell server
- Centos7 Start Error: Entering emergency mode.Exit the shell to continue
- Windows writes shell script and executes shell error [Solved]
- [Solved] ERROR: The kernel module failed to load, because it was not signed by a key that is trusted by the
- [Solved] SSH Startup Error: unable to load host key /etc/ssh/ssh_host_ed25519_key bad permissions
- Prompt “entering emergency mode. Exit the shell to continue” if the Linux operating system does not start normally
- [Solved] Linux ECDSA key Error: Host key verification failed
- [Solved] ImportError:lib***.so–cannot open shared object file: No such…(pycharm/clion Error but shell No Error)
- [Solved] Flask Error: RuntimeError: The session is unavailable because no secret key was set.
- Ubuntu shell Script syntax error near unexpected token `$‘{\r‘‘
- Shell Script syntax error near unexpected token `done’
- The semget function error: errno is set to 28 [How to Solve]
- [Solved] Module yaml error: Unexpected key in data: static_context
- [Solved] secureCRT Failed to Login Ubuntu20.04 Error: Key exchange failed
- How to Use Annotations in Flutter & Dart
- [Solved] Linux shell Script Error: syntax error near unexpected token `do
- Running shell script reports an error: “syntax error near unexpected token solution ‘”