Página 1 de 1

Pretty Print JSON Structure

Publicado: 20 Nov 2020 07:28
por sendai
Hi everyone.. any body can help me how to Pretty Print the JSON Data for easy reading?

like this:

Easy to Read

Imagen


here is the json data

{"person":[{"firstName":"Clark","lastName":"Kent","job": "Reporter","roll":20},{"firstName":"Bruce","lastName":"Wayne","job":"Playboy","roll":30},{"firstName":"Peter","lastName":"Parker","job": "Photographer","roll":40}]}


what i have now is i create a for loop like this:

filter = {"{", "}", ",", "},"}

for k,v in pairs (filter) do
tFilter = String.Find(x, v, 1, false)
if v == "{" then
x = String.Replace(x, v, "{\r\n ", false);
end
if v == "}" then
x = String.Replace(x, v, "\r\n }", false);
end
if v == "," then
x = String.Replace(x, v, ",\r\n ", false);
end
if v == "}," then
x = String.Replace(x, v, "},\r\n ", false);
end
end

im my example i will find the replace all character in the table but the result not really good..
hope others can share how to acheive? thanks..


Sendai

Re: Pretty Print JSON Structure

Publicado: 21 Nov 2020 03:13
por sendai
here is the clean solutions i figure out:

fil = {"{", "}", ",", "},"}
rep = {"{\r\n ", "\r\n }", ",\r\n ", "},\r\n "}

for k,v in pairs (fil) do
x = String.Replace(x, v, rep[k], false);
end

Thanks hope it helps...

Re: Pretty Print JSON Structure

Publicado: 05 May 2021 05:11
por Agotaras123
encontraste alguna solución a tu problema?

Re: Pretty Print JSON Structure

Publicado: 05 May 2021 16:18
por dripro
Agotaras123 escribió:
05 May 2021 05:11
encontraste alguna solución a tu problema?
Hello friend, how are you? where can I see the error in that code?

Re: Pretty Print JSON Structure

Publicado: 08 May 2021 04:25
por Agotaras123
que tal Amigo, el error es que el plugin de JSON no hace todo como debe de ser te dejo un ejemplo de como debe de convertir el código.


este es una informacion formateada para JSON

Código: Seleccionar todo

{
  "declaracion":{
    "general":{
      "rucEmpresa":"",
      "cotizacionUSD":""
    },
    "aduana":{
      "idAduanaIngreso":"0004",
      "idAduanaDespacho":"0004",
      "idDeclaracion":"",
      "fechaAceptDecla":"2021-02-03"
    },
    "importador":{
      "nomImportador":"SUPER TECHNOLOGIES HONDURAS S DE R L",
      "rtnImportador":"0801-9998-403710",
      "numRegImportador":"08019998403710",
      "dirImportador":"FLORENCIA SUR CALLE PRINCIPAL 2",
      "ciuImportador":"TEGUCIGALPA",
      "paisImportador":"HN",
      "telImportador":"22324784",
      "faxImportador":"22217534",
      "emailImportador":"[email protected]",
      "nivComImportador":"DIS",
      "otrNivComImportador":"N\/A"
    },
    "proveedor":{
      "idProveedor":"SUPER TECHNOLOGIES, INC.",
      "nombre":"SUPER TECHNOLOGIES, INC.",
      "direccion":"2200 NW 102ND AVENUE, BAY #6 , FL 33172",
      "ciudad":"MIAMI",
      "pais":"US",
      "telefono":"305-594-2200",
      "fax":"NO TIENE",
      "email":"[email protected]",
      "condComercial":"DT",
      "otraCondicion":"N\/A"
    },
    "intermediario":{
      "nomIntermediario":"",
      "dirIntermediario":"",
      "ciuIntermediario":"",
      "paisIntermediario":"",
      "telIntermediario":"",
      "faxIntermediario":"",
      "emailIntermediario":"",
      "tipoIntermediario":"",
      "otroIntermediario":""
    },
    "transaccion":{
      "lugarEntrega":"MIAMI",
      "paisEntrega":"US",
      "condicionEntrega":"FOB",
      "versionCondicionEntrega":"2020",
      "numContrato":"",
      "fechaContrato":"",
      "formaEnvio":"TT",
      "otrFormaEnvio":"N\/A",
      "indPagoEfectuado":"N",
      "formaPago":"TB",
      "otraFormaPago":"N\/A",
      "lugarEmbarque":"USMIA",
      "paisEmbarque":"US",
      "paisExportacion":"US",
      "fechaExportacion":"2021-01-21",
      "monedaTransaccion":"USD",
      "tipoCambioMonedaTrans":""
    },
    "condiciones":{
      "restricciones":"N",
      "descRestricciones":"",
      "contraPrestacion":"N",
      "descContraPrestacion":"",
      "ventaCondicionada":"N",
      "vinculacionCompVend":"N",
      "tipoVinculacion":"",
      "vincInfluenciaPrecio":"N",
      "pagoDescuentos":"N",
      "conceptoPorPagosDesc":"",
      "existenCanones":"N",
      "razonPago":"",
      "resolAdministrativa":"",
      "fechaResolucion":"",
      "numeroCasillaResol":""
    },
    "determinacion":{
      "importeFactura":"4,690.74",
      "montoPagosInd":"0.00",
      "importeContraprestacion":"0.00",
      "importeReversion":"0.00",
      "gastosComisiones":"0.00",
      "gastosEmbalajes":"0.00",
      "valorMaterialesIncorporados":"0.00",
      "valorHerramientasProd":"0.00",
      "valorMaterialesConsumidos":"0.00",
      "valorIngenieriaExt":"0.00",
      "valorDerLicencia":"0.00",
      "importeTransporte":"512.00",
      "importeCargaManipulacion":"0.00",
      "importeSeguro":"70.36",
      "importeAsistenciaTecnica":"0.00",
      "importeTransportePuerto":"0.00",
      "importeImpuestos":"0.00",
      "importeIntereses":"0.00",
      "importeOtrasDeducciones":"0.00",
      "importeRealPagado":"4,690.74",
      "importeAjustes":"582.36",
      "totalDeducciones":"0.00",
      "valorAduana":"5,273.10"
    },
    "facturas":[
      {
        "informacion":{
          "nroFactura":"987654",
          "fecha":"2020-12-14",
          "totalFlete":"0.00",
          "totalSeguro":"0.00",
          "indProrrateo":false
        },
        "items":[
          {
            "nroItem":"1",
            "cantComercial":"15",
            "uniComercial":"18",
            "designacionComercial":"IMPRESORAS ",
            "caracteristicasMercancias":"MULTIFUNCIONALES",
            "marcaMercancias":"CANON",
            "modeloMercancias":"PTRCANE402",
            "estadoMercancias":"NU",
            "paisOriMercancias":"VN",
            "posArancelaria":"8443.31.00.00.00",
            "precioUnitario":"24.1500",
            "totalFobUnitario":"362.2500",
            "importeFlete":"0.00",
            "importeSeguro":"0.00",
            "importeOtrosGastos":"0.00",
            "errors":{}
          },
          {
            "nroItem":"2",
            "cantComercial":"35",
            "uniComercial":"18",
            "designacionComercial":"IMPRESORAS ",
            "caracteristicasMercancias":"MULTIFUNCIONALES",
            "marcaMercancias":"CANON",
            "modeloMercancias":"PTRCAN301",
            "estadoMercancias":"NU",
            "paisOriMercancias":"VN",
            "posArancelaria":"8443.31.00.00.00",
            "precioUnitario":"35.0000",
            "totalFobUnitario":"1,225.0000",
            "importeFlete":"0.00",
            "importeSeguro":"0.00",
            "importeOtrosGastos":"0.00",
            "errors":{}
          },
          {
            "nroItem":"3",
            "cantComercial":"21",
            "uniComercial":"18",
            "designacionComercial":"IMPRESORAS ",
            "caracteristicasMercancias":"MULTIFUNCIONALES",
            "marcaMercancias":"CANON",
            "modeloMercancias":"PTRCANE471",
            "estadoMercancias":"NU",
            "paisOriMercancias":"VN",
            "posArancelaria":"8443.31.00.00.00",
            "precioUnitario":"37.4400",
            "totalFobUnitario":"786.2400",
            "importeFlete":"0.00",
            "importeSeguro":"0.00",
            "importeOtrosGastos":"0.00",
            "errors":{}
          },
          {
            "nroItem":"4",
            "cantComercial":"15",
            "uniComercial":"18",
            "designacionComercial":"IMPRESORAS ",
            "caracteristicasMercancias":"MULTIFUNCIONALES",
            "marcaMercancias":"CANON",
            "modeloMercancias":"PTRCAN6810",
            "estadoMercancias":"NU",
            "paisOriMercancias":"TH",
            "posArancelaria":"8443.31.00.00.00",
            "precioUnitario":"25.1500",
            "totalFobUnitario":"377.2500",
            "importeFlete":"0.00",
            "importeSeguro":"0.00",
            "importeOtrosGastos":"0.00",
            "errors":{}
          },
          {
            "nroItem":"5",
            "cantComercial":"40",
            "uniComercial":"18",
            "designacionComercial":"IMPRESORAS ",
            "caracteristicasMercancias":"MULTIFUNCIONALES",
            "marcaMercancias":"EPSON",
            "modeloMercancias":"PTRCANEPS310",
            "estadoMercancias":"NU",
            "paisOriMercancias":"TH",
            "posArancelaria":"8443.31.00.00.00",
            "precioUnitario":"15.5000",
            "totalFobUnitario":"620.0000",
            "importeFlete":"0.00",
            "importeSeguro":"0.00",
            "importeOtrosGastos":"0.00",
            "errors":{}
          },
          {
            "nroItem":"6",
            "cantComercial":"55",
            "uniComercial":"18",
            "designacionComercial":"IMPRESORAS ",
            "caracteristicasMercancias":"MULTIFUNCIONALES",
            "marcaMercancias":"CANON",
            "modeloMercancias":"PTRCAN2410",
            "estadoMercancias":"NU",
            "paisOriMercancias":"VN",
            "posArancelaria":"8443.31.00.00.00",
            "precioUnitario":"24.0000",
            "totalFobUnitario":"1,320.0000",
            "importeFlete":"0.00",
            "importeSeguro":"0.00",
            "importeOtrosGastos":"0.00",
            "errors":{}
          }
        ]
      }
    ]
  },
  "usuario_id":""
}

y esto no lo hace el plugin solo te convierte a json de forma errónea.

Re: Pretty Print JSON Structure

Publicado: 09 May 2021 01:03
por abood1987
Agotaras123 escribió:
08 May 2021 04:25
que tal Amigo, el error es que el plugin de JSON no hace todo como debe de ser te dejo un ejemplo de como debe de convertir el código.
I came very close to finding the correct way to deal with this problem, but I need some time to completely solve the problem. I know that I was too late to present a solution, but many concerns are. :friends:

Re: Pretty Print JSON Structure

Publicado: 09 May 2021 01:55
por abood1987
مرحبا Agotaras123 :friends:
Due to the weakness of the Internet, I now put my findings as follows:
In the ON GLOBAL event we put the JSON code:

HIDE: ON
Hidebb Message Hidden Description


Then we put a button in the application with its name, for example JSON_Decode, to put this code inside as follows:

HIDE: ON
Hidebb Message Hidden Description


The result is displayed in the input, so you have to put Input1 into the application and then see the result yourself

The internet is so bad I can't put apz so tell me your comment if I'm on my way to reach a full solution

:friends:

sendai escribió:
20 Nov 2020 07:28

here is the json data

{"person":[{"firstName":"Clark","lastName":"Kent","job": "Reporter","roll":20},{"firstName":"Bruce","lastName":"Wayne","job":"Playboy","roll":30},{"firstName":"Peter","lastName":"Parker","job": "Photographer","roll":40}]}
You can find this for testing in the button code, read it carefully

Re: Pretty Print JSON Structure

Publicado: 10 May 2021 19:04
por Agotaras123
que tal Abood no quiero decodificar lo que quiero es codificar lo que tengo en un formulario que cuenta con input,combobox,grid toda esa información la quiero pasar a formato JSON deje el codigo JSON de ejemplo de como debería de quedar.


muchas gracias por tu tiempo.

Re: Pretty Print JSON Structure

Publicado: 10 May 2021 20:44
por dripro
:friends: Olá colega

tblvalue = {"intermediario",
"nomIntermediario",
"dirIntermediario",
"ciuIntermediario",
"paisIntermediario",
"telIntermediario",
"faxIntermediario",
"emailIntermediario",
"tipoIntermediario",
"otroIntermediario"}



JSONEn = json.encode(tblvalue);
JSONEn = String.Replace(JSONEn, "[", "{", false);
JSONEn = String.Replace(JSONEn, "]", "}", false);
JSONEn = String.Replace(JSONEn, ",", ":", false);
JSONEn = String.Replace(JSONEn, ":", ':"",\r\n', false);

JSONEn = String.Replace(JSONEn, '{"', '"', false);
JSONEn = String.Replace(JSONEn, '"'..tblvalue[1]..'":"",', '"'..tblvalue[1]..'":{', false);
JSONEn = String.Replace(JSONEn, '"}', '":""},', false);


Input.SetText("Input1", JSONEn);

você só precisar aprender usar o Replace nisso, veja esse exemple

Re: Pretty Print JSON Structure

Publicado: 16 Ago 2021 04:11
por DhiegoHelPP
gracias mi amigo
:num1: