-1

Im trying to remove a new line from a string like so:

jsonata_expr = r'''{
    "ips": *.*.ip_addr,
    "vlans": $join(vlans.($string(vlan_id)), ","),
    "date": $now()
}'''

jsonata_expr.strip('\n')
'{\n    "ips": *.*.ip_addr,\n    "vlans": $join(vlans.($string(vlan_id)), ","),\n    "date": $now()\n}'

But as you can see the newlines are still there. What am I doing wrong?

felix001
  • 15,341
  • 32
  • 94
  • 121

1 Answers1

2

strip will work only with leading and trailing positions. So one solution is to replace newline character with empty string.

jsonata_expr.replace("\n", "")

Please note that this will produce a new string object(In python, strings are Immutable by design)

Yevhen Kuzmovych
  • 10,940
  • 7
  • 28
  • 48
Abdul Niyas P M
  • 18,035
  • 2
  • 25
  • 46