How to map a json string to another json string?

Asked

Viewed 91 times

1

Is there any way to map a json string to another json string?

The goal is to take the value of one json property and set it in another json property.

Exe;

I have the json.

{
    "codigo":0,
    "descricao":"string",
    "limiteDiario":0,
    "limiteMensal":0,
    "agencia":0,
    "conta":0,
    "codigoDoProduto":0,
    "entidadePrincipal":{
        "codigo":0,
        "tipo":"string",
        "pessoa":{
            "codigo":0,
            "nome":"string",
            "documento":{
                "codigo":0,
                "numero":"string",
                "dataDeEmissao":"2018-04-05T19:14:32.279Z",
                "orgaoEmissor":"string",
                "tipoDeDocumento":0
            },
            "tipoDePessoa":0,
            "situacao":0
        }
    }
}

And I want to take the value of the field description to set in the field description from another json. the field guy in the typDeControl and so on.

{
    "codigo":0,
    "descricao":"string",
    "parametros":{
        "codigo":0,
        "tipoDeControle":0,
        "numero":0,
        "orgaoEmissor":"string",
        "tipoDePessoa":0
    }
}

I see you have some libraries like https://github.com/joelvh/json2json and https://www.npmjs.com/package/json-mapper, but I didn’t quite understand how to use.

  • how do you want to make using c# it seems easier to convert Json to object using the class System.Web.Script.Serialization.JavaScriptSerializer and use a mapper in C#, like https://automapper.org/ to map to another object with properties with similar names

  • @Ricardopunctual, it would be cool, but this will be riding on a gateway and it will be several json that will come, my idea is to create Templates to do this for each json...if to use the automapper would have to create templates for all json.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.