Six Stars

Json replace

Hi 

 

I have my json response as show in pic

i want to remove the Selected part and how can it be removed using talend.

Please do respond as early as possible

 

Thanks

Deepthi

 

 

 

 

 

6 REPLIES
Seven Stars

Re: Json replace

Hi Deepthi,

 

You can add screen grabs directly into your posts using the "Photos" button, which makes things easier for anyone reading them.

 

Whilst depending on the data and structure of your JSON file, it may be possible to directly remove sections like this using raw file input/output components and Regular Expressions within a tReplace, this certainly isn't recommended or reliable, and by far the best way to do what you're asking is by using the JSON file input and output components, and then manipulating the data properly within the job, as per my reply to your "JSON Manipulation" question:

 

https://community.talend.com/t5/Design-and-Development/JSON-Maniplation/m-p/39594#M11138

 

Regards,

 

 

Chris

Six Stars

Re: Json replace

Hi Team

 

 


ciw1973 wrote:

Hi Deepthi,

 

You can add screen grabs directly into your posts using the "Photos" button, which makes things easier for anyone reading them.

 

Whilst depending on the data and structure of your JSON file, it may be possible to directly remove sections like this using raw file input/output components and Regular Expressions within a tReplace, this certainly isn't recommended or reliable, and by far the best way to do what you're asking is by using the JSON file input and output components, and then manipulating the data properly within the job, as per my reply to your "JSON Manipulation" question:

 

https://community.talend.com/t5/Design-and-Development/JSON-Maniplation/m-p/39594#M11138

 

Regards,

 

 

Chris



these part from attached file

how can we implement using talend

Thanks

Deepthi 

 

Seven Stars

Re: Json replace

Hi Deepthi,

 

Firstly, you absolutely should not be posting anything to a public forum which includes actual data, as it appears the file you have attached to your post does.

 

Secondly, I really would encourage you to learn how the tFileInputJSON and tFileOutputJSON components work, as you will then be able to do everything you require in the correct way.

 

I have suggest two approaches which will enable you to do this, but it seems you're not asking for help, and are instead asking the community to do your work for you.

 

 

There are plenty of paid consultants who I'm sure would be more than happy to implement this for you.

 

Regards,

 

Chris

Seven Stars

Re: Json replace

OK, I had ten minutes to spare whilst waiting for something to run, so have put together a quick example of how this can be done FOR YOUR SPECIFIC FILE ONLY using the simple replace approach. This is unlikely to be useful for anything more complicated.

 

Read in the file using a tFileInputRaw, with the Mode set to "Read the file as a string", which should be the default:

 

tFileInputRaw.png

 

This will give you the content as an Object, but you'll want a string, so use a tConvertType with the schema set as follows:

 

tConvertType_Schema.png

 

And just tick "Auto Cast" on the component:

 

tConvertType.png

 

Next is the tReplace, which we use in "Advanced mode" to allow matching using a Regular Expression, and we replace whatever's matched with an empty string to remove it:

 

tReplace2.png

 

 

The Regular Expression is:

 

    "transactionDetail":\{.*?\},

 

But in the component we need to wrap this in double quotes, and escape (add a backslash before) the existing double quotes and slashes in the Regular Expression, which gives us:

 

    \"transactionDetail\":\\{.*?\\},

 

This will match a section of the string which begins with  "transactionDetail":{  and ends at the next closing curly brace  }  it finds followed by a comma. This completely matches the section of the JSON string you wish to remove.

 

Then it's simply a case of outputting the string to a file using tFileOutputRaw:

 

tFileOutputRaw.png

 

Six Stars

Re: Json replace

Hi 

 

Thanks for your result

I have achieved the same in different approch

tExtractJson.PNG

I have given you a dummy file,the purpose i have kept the file  is to make your understanding better

My intension is not to design a job,ok The approch you have given before is not clearly so i have reposted my question

If you are not patient enough to explain you cant be a good guide,Agreed you have better knowledge than me but please so remember you cant comment to your wish in a public forum.

 

Once again thanks a lo for your response

 

Seven Stars

Re: Json replace

Deepthi,

 

You asked how to do something in Talend, and I suggested two approaches - one a robust, reliable way which would require some effort on your part to learn two new, and in fairness, quite complex components; and another, which whilst hardly ideal, was a quick way to achieve your specific goal using simple components which I thought you would likely already know. These were certainly not the only approaches, but both would have worked.

 

Your response was, in effect, "I'm ignoring your suggestions, here's my file, how do I do it?"

 

If you were looking for help, rather than a completed solution (and your post before you removed the attachment and some of the text, suggested that you were having problems) you could have asked for further details regarding either of my suggestions or help with the components involved, which I'd have been more than happy to provide, as I'm sure would other forum members, but you didn't.

 

Maybe it's just down to you choice of language, but to me you came across as rather rude (although your edited post after I'd already replied was less so) and as though you couldn't be bothered making an effort. There is no teaching a student who doesn't want to learn.

 

In all honesty, the quick solution I provided was not for your benefit, but for anyone finding this thread in future.

 

Whilst I have concerns about the approach you've taken, if it works, then I'm glad you found a solution to your problem.