Skip to content

toJSON() does not use json_name #1245

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
redstubble opened this issue Jun 13, 2019 · 0 comments · May be fixed by #1825
Open

toJSON() does not use json_name #1245

redstubble opened this issue Jun 13, 2019 · 0 comments · May be fixed by #1825

Comments

@redstubble
Copy link

protobuf.js version: "protobufjs": "^6.8.8",

decode message to JSON should use json_name as key.

pbjs -t json-module ...

Generates the following

fields: {
              timestamp: {
                type: "uint64",
                id: 1,
                options: {
                  json_name: "t"
                }
              },
              latitude: {
                type: "double",
                id: 2,
                options: {
                  json_name: "lat"
                }
              },
              longitude: {
                type: "double",
                id: 3,
                options: {
                  json_name: "lon"
                }
              },
              altitude: {
                type: "double",
                id: 4,
                options: {
                  json_name: "alt"
                }
              },
              fields: {
                type: "uint32",
                id: 15,
                options: {
                  json_name: "f"
                }
              }
            }

However whenever I call toJSON() on a message that has been decoded I get strings that are not json_name values. I cannot find any options to create the object with keys reflecting these json_names.

  const test = root.lookupType("com.<>.<>");
  const bin = readBinaryFile("./<>.bin");
  const mess = test.decodeDelimited(bin);
  console.log(mess.toJSON)

Logs

{
  "timestamp": "1557957939176",
  "latitude": 32.305504145820564,
  "longitude": -64.8585479141154,
  "altitude": 65.5
}
@michaelbgreen michaelbgreen linked a pull request Oct 12, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant