0

I am interested in highlighting a specific portion of the json document based on some arbitrary matching algorithm. For example

{
  "text" : "hello world"
}

I searched for "hello" and above json document has hello in it. How to highlight that particular portion "hello" while displaying the document on the terminal using python? Also, the json has to be pretty printed.

Expected

{
  "text" :  " `hello` world"
}

Text that is qoutes should be displayed in red color.

hello world
  • 660
  • 2
  • 6
  • 25

1 Answers1

2

I can't comment :(

The answer here might be able to help you: Print in terminal with colors using Python?

For example, you could use termcolor (if you are using a linux style terminal) and replace "hello" with colored("hello", "red")

from termcolor import colored

sample_text = "colored hello there !"
print(sample_text)

print(sample_text.replace("hello", colored("hello", "red")))
Community
  • 1
  • 1
khazhyk
  • 1,738
  • 1
  • 18
  • 13