fork download
  1. from io import StringIO
  2. import re
  3.  
  4. reader = StringIO("""{
  5. "Bounds": [
  6. {
  7. "HasClip": true,
  8. "Lang": "no",
  9. "Page": 0,
  10. "Path": "//Document/Sect[2]/Aside/P",
  11. "Text": "Potsdam, den 9. Juni 2021 ",
  12. "TextSize": 12.0
  13. }
  14. ],
  15.  
  16. },
  17. {
  18. "Bounds": [
  19. {
  20. "HasClip": true,
  21. "Lang": "de",
  22. "Page": 0,
  23. "Path": "//Document/Sect[3]/P[4]",
  24. "Text": "this is some text ",
  25. "TextSize": 9.0,
  26. }
  27. ],
  28. }""")
  29.  
  30.  
  31. text = reader.read()
  32. pattern = r'"Path": "(.*?)"'
  33. replacement = '"Path": "\\1/1A"'
  34. text = re.sub(pattern, replacement, text)
  35.  
  36. print(text)
Success #stdin #stdout 0.03s 9680KB
stdin
Standard input is empty
stdout
{
    "Bounds": [
        {
            "HasClip": true,
            "Lang": "no",
            "Page": 0,
            "Path": "//Document/Sect[2]/Aside/P/1A",
            "Text": "Potsdam, den 9. Juni 2021 ",
            "TextSize": 12.0
        }
    ],
    
},
{
    "Bounds": [
        {
            "HasClip": true,
            "Lang": "de",
            "Page": 0,
            "Path": "//Document/Sect[3]/P[4]/1A",
            "Text": "this is some text ",
            "TextSize": 9.0,
        }
    ],
}