Cant replace \r\n

Hi! I recently made an OCR app and I

was wondering why I couldn't filter \r\n out of the response.

From the little part of your OCR response I could see in your REPLACE ALL text block, it looks like you are getting back JSON text from the OCR read.

The Web component has blocks to decode JSON into a dictionary, for easy lookup of parts of the response.

If you post one of your full OCR responseContent values here as text, and tell us which part you want, we can probably show you an easier way to extract it.

Hi! The full JSON Response is as follows

{"ParsedResults":[{"TextOverlay":{"Lines":[],"HasOverlay":false,"Message":"Text overlay is not provided as it is not requested"},"TextOrientation":"0","FileParseExitCode":1,"ParsedText":"F.Underwood 12:08\r\nI have something for you,\r\nmeet toni ht.\r\n","

I bolded the parts Im trying to extract. Thanks!

Did you trim the end of your responseContent, or was it clipped by some length limit?

It is unbalanced.

No i didnt trim it. And as far as I know there is no length limit.

For malformed JSON, we have to fall back on the @Taifun parse procedure:


P.S. These blocks can be dragged directly into your Blocks Editor workspace.

See Download Block Images for a demo.

1 Like

Regardless of how you parse it, I suspect you are butting up against a length limit for whatever type of OCR code you are using.

I recommend further testing on your part with longer inputs, checking the lengths of the responseContents.

Awesome! and sorry to ask but how would I incorporate it so the parsed text shows up in the text box?

These are draggable blocks.

The first upload, with the fancy REPLACE block, had all the logic, so pull that into a SET Label.Text block for where you want the output.

You should be familiar with the Companion's Do It facility by now.

P.S. These blocks can be dragged directly into your Blocks Editor workspace.

See A way to group projects by theme - #10 by ABG
for a demo.

For more about this, please see this help page.

1 Like

Right on. So something like this?

Even more important than coding: ripping out bad code.

Yeah, i noticed that after i posted it, Sorry! But whenever I add the Set Variable to the procedure the \r\n doesn't get removed for some reason. it only works when myJSON isn't set to something else. Any ideas?

If all the json stuff is constant with an ocr return you could try this:

For debugging purposes, I propose adding some extra global variables and Labels to show the partial progress of the various steps of text transformation:

  • the parse procedure, input and output
  • the replace all mappings block.

P.S. I am not sure that \r\n is handled right, compared to first removing \r then removing \n via a pipeline of replace blocks.