thrift-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Magesh Dhasayyan <>
Subject thrift JSON serialization question
Date Wed, 13 Mar 2013 09:15:57 GMT

I'm trying to use thrift for an application that uses JSON. For example
I've listed below a sample thrift struct (Foo) and it's usage in a C++
program. I want the output of the program to be {"bar": 1024} and NOT
{"1":{"i32":1024}}. Is it possible using thrift libraries?

// file: hello_world.thrift
struct Foo {
  1: i32 bar;

// file: hello_world.cpp
#include <iostream>
#include <thrift/transport/TBufferTransports.h>
#include <thrift/protocol/TJSONProtocol.h>
#include <thrift/protocol/TProtocolException.h>
#include <gen-cpp/hello_world_types.h>
int main() {
    namespace atp = apache::thrift::protocol;
    namespace att = apache::thrift::transport;
       transport(new att::TMemoryBuffer());
    atp::TJSONProtocol protocol(transport);
    Foo foo; = 1024;
    std::cout << transport->getBufferAsString()
              << std::endl;

// file: JSON-output.txt

Looking at the comments in
thrift-0.9.0/lib/cpp/src/thrift/protocol/TJSONProtocol.h, I suspect it's
not possible. But just wanted to check with thrift experts before I drop
the idea.


  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message