JSON object parsing and how to escape unicode characters

jayho

I'm fairly new to javascript and such so I don't know if this will be worded correctly, but I'm trying to parse a JSON object that I read from a database. I send the html page the variable from a python script using Django where the variable looks like this:

{
  "data":{
    "nodes":[
      {
        "id":"n0",
        "label":"Redditor(user_name='awesomeasianguy')"
      },
      ...
    ]
  }
}

Currently, the response looks like:

"{u'data': {u'nodes': [{u'id': u'n0', u'label': u"Redditor(user_name='awesomeasianguy')"}, ...

I tried to take out the characters like u&#39 with a replaceAll type statement as seen below. This however is not that easy of a solution and it seems like there has got to be a better way to escape those characters.

var networ_json = JSON.parse("{{ networ_json }}".replace(/u'/g, '"').replace(/'/g, '"').replace(/u"/g, '"').replace(/"/g, '"'));

If there are any suggestions on a method I'm not using or even a tool to use for this, it would be greatly appreciated.

rihardsp

Use the template filter "|safe" to disable escaping, like,

var networ_json = JSON.parse("{{ networ_json|safe }}";

Read up on it here: https://docs.djangoproject.com/en/dev/ref/templates/builtins/#safe

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to escape special characters in Groovy, excluding unicode

From Dev

How to escape Special Characters in JSON

From Dev

Automatically escape unicode characters

From Dev

Parsing Unicode JSON object in PHP 5.3

From Dev

Escape unicode characters in Go JSON so the output matches Python

From Dev

Parsing JSON using Pandas - issue with additional \ escape characters

From Dev

Parsing Json containing escape characters to JsonObject using Newtonsoft

From Dev

Dealing with Unicode characters in NSArray after parsing a JSON feed

From Dev

How to convert an ascii string with escape characters to its unicode equivalent

From Dev

How to escape the quotes in JSON Object?

From Dev

How to escape the quotes in JSON Object?

From Dev

Decode unicode escape characters with perl

From Dev

Decode unicode escape characters with perl

From Dev

Parsing for escape characters with a regular expression

From Java

How to escape special characters in building a JSON string?

From Dev

How to remove escape characters from a JSON String

From Dev

How to remove escape characters from Json string?

From Dev

How to escape new line characters for json?

From Dev

How do you correctly detect escape characters in a JSON object in Node.js?

From Dev

encode unicode characters to unicode escape sequences

From Dev

Parsing active record object to json with escape of single quote (apostrophe)

From Dev

Parsing: How do I strip out Unicode Characters?

From Dev

Convert special Characters to Unicode Escape Characters Scala

From Dev

Parsing XML with Unicode characters in Coldfusion

From Dev

Unicode in Python - parsing JSON

From Dev

JSON Document Escape Characters

From Dev

How to escape backslash in json object key

From Dev

How to escape a JSON object to feed into a JavaScript function?

From Dev

JSON Unicode escape sequence - lowercase or not?

Related Related

  1. 1

    How to escape special characters in Groovy, excluding unicode

  2. 2

    How to escape Special Characters in JSON

  3. 3

    Automatically escape unicode characters

  4. 4

    Parsing Unicode JSON object in PHP 5.3

  5. 5

    Escape unicode characters in Go JSON so the output matches Python

  6. 6

    Parsing JSON using Pandas - issue with additional \ escape characters

  7. 7

    Parsing Json containing escape characters to JsonObject using Newtonsoft

  8. 8

    Dealing with Unicode characters in NSArray after parsing a JSON feed

  9. 9

    How to convert an ascii string with escape characters to its unicode equivalent

  10. 10

    How to escape the quotes in JSON Object?

  11. 11

    How to escape the quotes in JSON Object?

  12. 12

    Decode unicode escape characters with perl

  13. 13

    Decode unicode escape characters with perl

  14. 14

    Parsing for escape characters with a regular expression

  15. 15

    How to escape special characters in building a JSON string?

  16. 16

    How to remove escape characters from a JSON String

  17. 17

    How to remove escape characters from Json string?

  18. 18

    How to escape new line characters for json?

  19. 19

    How do you correctly detect escape characters in a JSON object in Node.js?

  20. 20

    encode unicode characters to unicode escape sequences

  21. 21

    Parsing active record object to json with escape of single quote (apostrophe)

  22. 22

    Parsing: How do I strip out Unicode Characters?

  23. 23

    Convert special Characters to Unicode Escape Characters Scala

  24. 24

    Parsing XML with Unicode characters in Coldfusion

  25. 25

    Unicode in Python - parsing JSON

  26. 26

    JSON Document Escape Characters

  27. 27

    How to escape backslash in json object key

  28. 28

    How to escape a JSON object to feed into a JavaScript function?

  29. 29

    JSON Unicode escape sequence - lowercase or not?

HotTag

Archive