-1

I have this String value which is a Map of user to password

'{"userJohn":"1234","userLinda":"9876"}'

the string has a single quate from each side.

How can I extract the password of say, userLinda

2

1 Answer 1

0

# fishell
 ~ echo '\'{"userJohn":"1234","userLinda":"9876"}\'' | sed 's/^\'//' | sed 's/\'$//' | jq '.userLinda'
"9876"


# bash zsh
~ echo "'"'{"userJohn":"1234","userLinda":"9876"}'"'" | sed "s/^'//" | sed "s/'$//" | jq '.userLinda'
"9876"
Sign up to request clarification or add additional context in comments.

5 Comments

echo '\' emits a literal double quote; that's hardly what you wanted to demonstrate.
What do you mean,It is single quote on my computer
Perhaps you transcribed it incorrectly. Demo: ideone.com/0mJy26
yeah, I get it, i use fishell, it is fine, I will change the answer
Adding to the confusion, I meant a literal backslash. Sorry and thanks for the update. Perhaps the Fish solution should not be at the top of the answer, though - the question is clearly tagged sh

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.