Convert Protobuf response to JSON in NodeJS
Asked Answered
F

1

6

How do we convert Protobuf response (eg. from Bigtable NodeJS Client) to JSON/String with correct braces. There are some resources for Python or Java(https://code.google.com/archive/p/protobuf-java-format/) but none for NodeJS yet which I have found. I am fairly new to Bigtable and NodeJS.

Faultfinding answered 26/9, 2018 at 22:7 Comment(0)
S
8

I'm not an expert in nodejs, but it seems like the node protobuf library contains a toObject method that will give you a plain javascript object which you can pass to JSON.stringify():

https://www.npmjs.com/package/protobufjs#usage

Selinaselinda answered 27/9, 2018 at 15:36 Comment(1)
Unfortunately the toObject encoding doesn't correctly implement all fields as it should be the proto documentation. E.g. TimeStamp should be returned as an ISO timestamp, but instead is an object with properties of seconds and nanosLaws

© 2022 - 2024 — McMap. All rights reserved.