Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

270
Visualizações
gRPC: Unknown JSON as input and output

I'm new to gRPC, I'm trying to expose gRPC server in which and rpc does not have known shape before hand.

Requirement is that particular field can have any value present in it.

Ex: file.proto

syntax = "proto3";

import "google/protobuf/struct.proto";

string corr_id = 1;
google.protobuf.Struct message = 2;

When i went through the docs there is no way we can create gRPC server without knowing the fields before hand. For this struct to work, i'm doing the following conversion and making it work.

Actual JSON Object:

{
  name: "wer",
  age: 28,
  hobbies: ["Cricket", "Tea"],
  key: {
     value1: 89,
     value2: "sure next"
  }
}

gRPC Server Requires this below conversion:

{
  "fields": {
    "name": {
      "stringValue": "wer"
    },
    "age": {
      "numberValue": 28
    },
    "hobbies": {
      "listValue": {
        "fields": [
          "Cricket",
          "Tea"
        ]
      }
    },
    "key": {
      "structValue": {
        "fields": {
          "value1": {
            "numberValue": 89
          },
          "value2": {
            "stringValue": "sure next"
          }
        }
      }
    }
  }
}

Is there util available already to do this conversion ? OR is there any other way i can achieve this without the conversion to make gRPC server parse the request ?

Imagine what i have to do for the below json ?

{
    name: "Sathish",
    age: 28,
    address: [
      {
        is_primary: true,
        name: "address1"
      },
      {
        is_primary: false,
        name: "address2"
      }
    ],
    hobbies: ["Cricket", "Tea"],
    movies: {
      liked: ["Re"],
      unliked: ["Te"]
    },
    key: {
      value1: 89,
      value2: "sure next"
    }
  }

Note: I'm using @grpc/grpc-js package alone for now.

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda