kyleabaker
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2014
12:43 PM
JSON and Regex Escape Characters
I'm parsing a JSON response and am finding that some year strings are returned with the following format in JSON:
...,"Year":"2009\u2013",...
When I set year = Content.Year I'd like to replace the \u with a dash (ex. 2009-2013), but its showing up as "2009-" currently and I'm not able to even see the second year. I see that \u appears to be an escape character. Any idea how I can get this date range formatted correctly?
...,"Year":"2009\u2013",...
When I set year = Content.Year I'd like to replace the \u with a dash (ex. 2009-2013), but its showing up as "2009-" currently and I'm not able to even see the second year. I see that \u appears to be an escape character. Any idea how I can get this date range formatted correctly?
6 REPLIES 6
destruk
Streaming Star
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2014
01:11 PM
Re: JSON and Regex Escape Characters
You could, before parsing, do a string replace on the data, and send the result to the JSON parser.

RokuMarkn
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2014
01:12 PM
Re: JSON and Regex Escape Characters
You just want to replace the string "\u" with "-", right? It would help if you showed what code you've tried, but this will work. Note that since backslash is a regex metacharacter, you have to escape it.
--Mark
regex = CreateObject("roRegex", "\\u", "")
year = regex.Replace(year, "-")
--Mark
kyleabaker
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2014
02:02 PM
Re: JSON and Regex Escape Characters
Mark,
That's the exact regex that I was trying as well, however, its not doing what we're expecting here. Below is what I see in the debug console when I print Content.Year. Then I execute this regex and print that below. Doesn't seem to be replacing anything and you can see the Ç char is printed for some reason.
Is the "\u2013" being displayed as this Ç character?
That's the exact regex that I was trying as well, however, its not doing what we're expecting here. Below is what I see in the debug console when I print Content.Year. Then I execute this regex and print that below. Doesn't seem to be replacing anything and you can see the Ç char is printed for some reason.
2009 Ç
2009 Ç
Is the "\u2013" being displayed as this Ç character?
kyleabaker
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2014
02:05 PM
Re: JSON and Regex Escape Characters
"destruk" wrote:
You could, before parsing, do a string replace on the data, and send the result to the JSON parser.
That's a possible solution, but seems like I should be able to handle this data without processing it before JSON parsing. If all else fails I'll give that a shot.

NewManLiving
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2014
03:34 PM
Re: JSON and Regex Escape Characters
You can try rostring tokenize Solved a few similar problems for me
My Channels: 2D API Framework Presentation: https://owner.roku.com/add/2M9LCVC
Updated: 11-11-2015 - Completed Keyboard interface
The Joel Channel ( Final Beta )
Updated: 11-11-2015 - Completed Keyboard interface
The Joel Channel ( Final Beta )
EnTerr
Roku Guru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2014
03:54 PM
Re: JSON and Regex Escape Characters
"kyleabaker" wrote:
I'm parsing a JSON response and am finding that some year strings are returned with the following format in JSON:
...,"Year":"2009\u2013",...
When I set year = Content.Year I'd like to replace the \u with a dash (ex. 2009-2013), but its showing up as "2009-" currently and I'm not able to even see the second year. I see that \u appears to be an escape character. Any idea how I can get this date range formatted correctly?
You guys, beating the wrong horse here.
There is no year "2013" in the string - rather \u2013 is a single character, EN DASH. Same as chr(&h2013) and chr(8211) if you want it in B/S. Due to looking as a year number, confusion is understandable. Apropos, \u2014 is EM DASH (dash with the width of letter "M").
It should be displayed as "2009-"; i suppose it means "2009 and later".
"kyleabaker" wrote:Yes, it is not replacing anything, because there is no r"\u" in the string. The display of EN DASH as tabs+Ç is some idiosyncrasy of the console, which i rather not dig into (could be the telnet protocol, terminal emulator etc).
Doesn't seem to be replacing anything and you can see the Ç char is printed for some reason.