Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

Create Json through plain text

avatar
New Contributor

Hello!

I am trying to separate a text to create a new JSON.

This is my text: 

"02Dxii+moRBTYIXpUJtAsA0101000000000000000000000000Dxii+moRBTYIXpUJtAsA01012021-09-20 10":"55":57.000705D00102{
   "idServico":"0",
   "versaoServico":"0",
   "idOperacao":"5136812",
   "versaoOperacao":"1",
   "plataformaProvedor":"CIC",
   "plataformaConsumidor":"JEE",
   "siglaProvedor":"CDC",
   "siglaConsumidor":"MOV",
   "topicoRequisicao":"BB.BSB.JEE.CIC.RQ.241.MOV.CDC.0.0.5136812.1",
   "topicoResposta":"BB.BSB.JEE.CIC.RP.241.MOV.CDC.0.0.5136812.1.AC11E985.61385B75166D17.303973",
   "hostname":"pxl1mov1g022.dispositivos.bb.com.br",
   "pid":"13803",
   "protocoloOperacao":"IIB",
   "transporteOperacao":"Rendezvous",
   "nivelSigilo":90,
   "chaveUsuario":"        ",
   "interfaceCNL":"0020",
   "implementacaoCNL":"0009",
   "chaveCNL":"2SSI6Ih8NWc2BSBQ00000000",
   "ipCliente":"187.59.182.244",
   "portaCliente":42119,
   "osName":"Linux",
   "osVersion":"4.12.14-95.3-default",
   "osArch":"amd64",
   "javaVersion":"1.8.0_172",
   "javaVm":"Java HotSpot(TM) 64-Bit Server VM",
   "javaVmVersion":"25.172-b11",
   "webserverName":"WebLogic",
   "webserverVersion":"12.2.1.2.0",
   "iibApiVersion":"1.7.0",
   "iibImplVersion":"1.7.0",
   "contextoAplicacao":"mov",
   "versaoAplicacao":"2.116.0.4",
   "tamanhoRequisicao":9
}

 

I'm trying to format for it.

{
   "hash":"02Dxii+moRBTYIXpUJtAsA0101000000000000000000000000Dxii+moRBTYIXpUJtAsA01012021-09-20 10:55:57.000705D00102",
   "idServico":"0",
   "versaoServico":"0",
   "idOperacao":"5136812",
   "versaoOperacao":"1",
   "plataformaProvedor":"CIC",
   "plataformaConsumidor":"JEE",
   "siglaProvedor":"CDC",
   "siglaConsumidor":"MOV",
   "topicoRequisicao":"BB.BSB.JEE.CIC.RQ.241.MOV.CDC.0.0.5136812.1",
   "topicoResposta":"BB.BSB.JEE.CIC.RP.241.MOV.CDC.0.0.5136812.1.AC11E985.61385B75166D17.303973",
   "hostname":"pxl1mov1g022.dispositivos.bb.com.br",
   "pid":"13803",
   "protocoloOperacao":"IIB",
   "transporteOperacao":"Rendezvous",
   "nivelSigilo":90,
   "chaveUsuario":"        ",
   "interfaceCNL":"0020",
   "implementacaoCNL":"0009",
   "chaveCNL":"2SSI6Ih8NWc2BSBQ00000000",
   "ipCliente":"187.59.182.244",
   "portaCliente":42119,
   "osName":"Linux",
   "osVersion":"4.12.14-95.3-default",
   "osArch":"amd64",
   "javaVersion":"1.8.0_172",
   "javaVm":"Java HotSpot(TM) 64-Bit Server VM",
   "javaVmVersion":"25.172-b11",
   "webserverName":"WebLogic",
   "webserverVersion":"12.2.1.2.0",
   "iibApiVersion":"1.7.0",
   "iibImplVersion":"1.7.0",
   "contextoAplicacao":"mov",
   "versaoAplicacao":"2.116.0.4",
   "tamanhoRequisicao":9
}

 

 Can you help me? thank you!

1 REPLY 1

avatar
Super Mentor

@VagnerBelfort 

 

From your example, it appears you are looking to modify only the first line of your input file and your modification seems pretty simple.

In that case, one possible solution is simply to use the ReplaceText processor to modify that first line to match you new modified structure.  Here is a ReplaceText processor configuration I used to accomplish your desired output:

MattWho_1-1633034028553.png

 

Search Value (Java regular Expression):

 

^"(.*?)":"(.*?)":(.*?)\{

 

Above contains 3 capture groups to capture the unique parts of your input we want to reuse.
Replacement Value:

 

{
	"hash":"$1:$2:$3",

 

Make note of the added line return.  All characters are literals except the $1, $2, and $3 which get replaced with the string form each of the three capture groups from the Java Regex.

Replacement Strategy:
Regex Replace
Evaluation Mode:
Line-by-Line
Line-by-Line Evaluation Mode:
First-Line

 

If you found this response assisted with your query, please take a moment to login and click on "Accept as Solution" below this post.

Thank you,

Matt