You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@nifi.apache.org by "Kuhfahl, Bob" <rk...@mitre.org> on 2018/08/16 13:43:24 UTC

ReplaceText regex question

I have to massage some JSON to pass into PutDatabaseRecord so I can insert the data into postgresql.
Postgres wants the identifers to have double quotes and it seems the values need to have single quotes (for the strings).

Sample JSON input:
    "producer_userid": "fdolomite",

Search Value:
(?<=\": )\"(.+)\"

Replacement Value:
'$1'

I can get a small java program to use the above and replace the “ (double quotes) around the value to ‘   (single quotes) e.g.:
    "producer_userid": ‘fdolomite’,

But… ReplaceText is not doing it.  I’ve tried surrounding the search & replacement values in quotes (pretty sure that was not the problem, but heh).
All I get in the log file is it moved the flow to success.
From reading the source code for ReplaceText , it’s using the Java Pattern() and replaceAll() so I think my sample program is doing the same work, including matcher.find()

So I must be missing something…

Re: ReplaceText regex question

Posted by Ed B <bd...@gmail.com>.
JSON format requires to use double quotes for string values.
Since you are using Put Db record, check you schema for JSON data. Most
probably there is a mismatch between data/json structure  and schema.

Regards,
Ed.

On Thu, Aug 16, 2018 at 9:43 AM Kuhfahl, Bob <rk...@mitre.org> wrote:

> I have to massage some JSON to pass into PutDatabaseRecord so I can insert
> the data into postgresql.
>
> Postgres wants the identifers to have double quotes and it seems the
> values need to have single quotes (for the strings).
>
>
>
> Sample JSON input:
>
>     "producer_userid": "fdolomite",
>
>
>
> Search Value:
>
> (?<=\": )\"(.+)\"
>
>
>
> Replacement Value:
>
> '$1'
>
>
>
> I can get a small java program to use the above and replace the “ (double
> quotes) around the value to ‘   (single quotes) e.g.:
>
>     "producer_userid": ‘fdolomite’,
>
>
>
> But… ReplaceText is not doing it.  I’ve tried surrounding the search &
> replacement values in quotes (pretty sure that was not the problem, but
> heh).
>
> All I get in the log file is it moved the flow to success.
>
> From reading the source code for ReplaceText , it’s using the Java
> Pattern() and replaceAll() so I think my sample program is doing the same
> work, including matcher.find()
>
>
>
> So I must be missing something…
>