# How can I add \\n(newline) In Json string

**URL:** <https://discuss.python.org/t/how-can-i-add-n-newline-in-json-string/19240>\
**Category:** Python Help\
**Created:** [September 19, 2022, 10:05am UTC](https://discuss.python.org/t/how-can-i-add-n-newline-in-json-string/19240 "2022-09-19T10:05:03Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![vbrozik](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/vbrozik/32/7423_2.png) [@vbrozik](https://discuss.python.org/u/vbrozik)\
**Post date:** [September 20, 2022, 11:44am UTC](https://discuss.python.org/t/how-can-i-add-n-newline-in-json-string/19240/4 "2022-09-20T11:44:04Z")

</div>

OK, this is an error message of the server. It has nothing to do with Python. You need to learn about what exactly the API expects in your request.

The text I have shown to you was just an example. I have no idea what your server accepts as requests.

In my example the trailing newline is just a whitespace which does not change the data inside JSON. If you need to have a newline inside a string inside JSON you can use the two literal characters `\n` which means you will need to double the backslash to tell Python to produce a single regular backslash (instead of treating it as a special character).

Let’s take my example and add `\n` to the property value of `firstName`:

```auto
data = '{"firstName": "John\\n"}\n'
# ^^--- These two characters create a newline
# character in the resulting string.
# ^^--- The two backslashes create a single literal
# literal backslash \ in the resulting string.
# The characters \n are then interpreted in JSON
# as a newline character.

```

---

_[View the full topic](https://discuss.python.org/t/how-can-i-add-n-newline-in-json-string/19240)._
