How to parse out a json file read using memoread

123 views
Skip to first unread message

laapc.issu...@gmail.com

unread,
Sep 16, 2025, 3:17:14 PMSep 16
to Harbour Users
Good afternoon,

We are working on a project where we need to parse out info from a json response file. We have been successful in reading the file and generating a character string from it, but we are getting a weird formatting issue when we try to read it using the memoread() function. Whenever we have the debugger on, it just adds a weird "e" character in front of the string and then it has a bunch of escape "\" characters added all throughout the string so it makes it impossible to really use hb_jsonencode() to read the string. This is very weird to us since, when you look at the file it is formatted correctly in the json format (admittedly it is cut off at the end; payload was too large). Is it possible to just get a string that represents that file formatted the way the file using memoread() or another function or is this just the way data is going to be returned to us while reading from  a file. Let us know if we need to clarify anything. 

Thanks in advance!
Lowenstein and Associates 

José M. C. Quintas

unread,
Sep 16, 2025, 3:29:43 PMSep 16
to harbou...@googlegroups.com
Not sure if text is wrong or use is wrong.

To read json format is hb_JsonDecode() and not hb_JsonEncode()


José M. C. Quintas
> --
>

Francesco Perillo

unread,
Sep 16, 2025, 3:50:28 PMSep 16
to harbou...@googlegroups.com
Isn't \e an escape sequence?

--
You received this message because you are subscribed to the Google Groups "Harbour Users" group.
Unsubscribe: harbour-user...@googlegroups.com
Web: https://groups.google.com/group/harbour-users
---
You received this message because you are subscribed to the Google Groups "Harbour Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to harbour-user...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/harbour-users/340b7c1e-bded-4644-9341-f1d64de46272n%40googlegroups.com.

berg...@gmail.com

unread,
Sep 16, 2025, 4:18:46 PMSep 16
to Harbour Users

What you describe matches three common issues:

  1. UTF-8 BOM at the start (EF BB BF) → appears as a weird first character in the debugger.

  2. Many backslashes → either just the escaped view in the debugger, or you actually loaded a JSON string that itself contains JSON (double-encoded).

  3. Cut off at the end → the file is not complete JSON; no decoder can parse that until you fix the upstream/paging.

MemoRead() itself doesn’t add characters, but for robust handling I recommend reading raw bytes and normalizing BOM/trailing control chars (including legacy ^Z / 0x1A). If the file contains a JSON string, decode it twice: first to get the string, second to get the object.

https://clipper2web.com/


FiveWin JSON Reader

Flatten JSON into PATH/TYPE/VALUE rows and view with XBROWSER. Includes a tolerant loader (BOM/^Z).

  • XBROWSER table view
  • BOM /^Z tolerant
  • Copy-ready source

laapc.issu...@gmail.com

unread,
Sep 16, 2025, 4:34:15 PMSep 16
to Harbour Users
By decoding it twice, do you mean running the hb_jsondecode() function on the string twice or something else?

Thanks,
Lowenstein and Associates

berg...@gmail.com

unread,
Sep 16, 2025, 5:07:47 PMSep 16
to Harbour Users
Have you tried reading with the jsonreader  https://clipper2web.com/pocs/fivewin-json-reader.html

Geoffrey Keenan

unread,
Sep 18, 2025, 2:08:24 AMSep 18
to Harbour Users
Are you aware that MEMOREAD() has a limitation of 65,535 bytes? One possible reason for an error.

I recently was using FREADSTR() in a low level function but sometimes it would provide a relatively short string. On inspection I found out that this function stops when it encounters a NUL character from the raw disk file. I solved that problem by using FREAD() within a loop.

pete....@gmail.com

unread,
Sep 18, 2025, 3:04:54 AMSep 18
to Harbour Users
On Thursday, 18 September 2025 at 09:08:24 UTC+3 Geoffrey Keenan wrote:
Are you aware that MEMOREAD() has a limitation of 65,535 bytes? One possible reason for an error.

 
No, 64K size limit is an (old-good) Clipper limitation. 
In Harbour there's no such a limit.  

```
MemoRead( <cFileName> ) cString
Returns the contents of <cFileName> (file of any size limited only by system memory rersouces) as a character string or empty string if <cFileName> not found.
```
(and the same apply, as well,  for harbour's extended function  hb_MemoRead() )



Reply all
Reply to author
Forward
0 new messages