Need advice about which tool to choose?Ask the StackShare community!

Apache Thrift

178
245
+ 1
0
JSON

1.9K
1.6K
+ 1
9
Add tool

Apache Thrift vs JSON: What are the differences?

Introduction

Apache Thrift and JSON are both popular data serialization formats used in web development. However, they have several key differences that differentiate them in terms of features and usage.

  1. Schema Definition: Apache Thrift requires a separate schema definition language to define the structure of the data being serialized and deserialized. This schema definition is used to generate code in various programming languages for data serialization and deserialization. On the other hand, JSON does not require a separate schema definition and can be used directly as a lightweight data interchange format.

  2. Data Types: Apache Thrift provides a wider range of primitive data types compared to JSON. It includes basic types like integers, floats, and booleans, as well as more complex types like enums, lists, and maps. JSON, on the other hand, supports only a limited set of data types including strings, numbers, booleans, arrays, and objects.

  3. Binary Protocol: Apache Thrift supports a binary protocol, which is a compact and efficient way of serializing data. This binary protocol reduces the size of the data being transmitted over the network and provides better performance compared to JSON. JSON, on the other hand, uses a plain-text format, which is less compact and efficient compared to the binary protocol.

  4. Code Generation: Apache Thrift generates code in multiple programming languages based on the provided schema definition. This generated code can be used to serialize and deserialize data in a language-specific manner. JSON, on the other hand, does not require any code generation as it can be directly parsed and serialized using built-in language features.

  5. Compatibility: Apache Thrift provides language-specific libraries for various programming languages, ensuring compatibility and seamless integration with different systems. JSON, on the other hand, has native support in almost all modern programming languages, making it highly compatible and widely used.

  6. Extensibility: Apache Thrift allows developers to define custom data types and functions as extensions to the core protocol. This extensibility feature provides flexibility in handling complex data structures and protocols. JSON, on the other hand, does not have a built-in extensibility mechanism and relies on external conventions or standards for handling complex data structures.

In summary, Apache Thrift offers a powerful and efficient data serialization framework with a separate schema definition language, binary protocol support, and code generation capabilities. JSON, on the other hand, is a lightweight and widely supported data interchange format that does not require a separate schema definition and can be used with minimal overhead.

Advice on Apache Thrift and JSON
Needs advice
on
JSONJSON
and
PythonPython

Hi. Currently, I have a requirement where I have to create a new JSON file based on the input CSV file, validate the generated JSON file, and upload the JSON file into the application (which runs in AWS) using API. Kindly suggest the best language that can meet the above requirement. I feel Python will be better, but I am not sure with the justification of why python. Can you provide your views on this?

See more
Replies (3)
Recommends
on
PythonPython

Python is very flexible and definitely up the job (although, in reality, any language will be able to cope with this task!). Python has some good libraries built in, and also some third party libraries that will help here. 1. Convert CSV -> JSON 2. Validate against a schema 3. Deploy to AWS

  1. The builtins include json and csv libraries, and, depending on the complexity of the csv file, it is fairly simple to convert:
import csv
import json

with open("your_input.csv", "r") as f:
    csv_as_dict = list(csv.DictReader(f))[0]

with open("your_output.json", "w") as f:
    json.dump(csv_as_dict, f)
  1. The validation part is handled nicely by this library: https://pypi.org/project/jsonschema/ It allows you to create a schema and check whether what you have created works for what you want to do. It is based on the json schema standard, allowing annotation and validation of any json

  2. It as an AWS library to automate the upload - or in fact do pretty much anything with AWS - from within your codebase: https://aws.amazon.com/sdk-for-python/ This will handle authentication to AWS and uploading / deploying the file to wherever it needs to go.

A lot depends on the last two pieces, but the converting itself is really pretty neat.

See more
Recommends
on
GolangGolang

I would use Go. Since CSV files are flat (no hierarchy), you could use the encoding/csv package to read each row, and write out the values as JSON. See https://medium.com/@ankurraina/reading-a-simple-csv-in-go-36d7a269cecd. You just have to figure out in advance what the key is for each row.

See more
Max Musing
Founder & CEO at BaseDash · | 1 upvotes · 313K views
Recommends
on
Node.jsNode.js
at

This should be pretty doable in any language. Go with whatever you're most familiar with.

That being said, there's a case to be made for using Node.js since it's trivial to convert an object to JSON and vice versa.

See more
Manage your open source components, licenses, and vulnerabilities
Learn More
Pros of Apache Thrift
Pros of JSON
    Be the first to leave a pro
    • 5
      Simple
    • 4
      Widely supported

    Sign up to add or upvote prosMake informed product decisions

    No Stats
    - No public GitHub repository available -

    What is Apache Thrift?

    The Apache Thrift software framework, for scalable cross-language services development, combines a software stack with a code generation engine to build services that work efficiently and seamlessly between C++, Java, Python, PHP, Ruby, Erlang, Perl, Haskell, C#, Cocoa, JavaScript, Node.js, Smalltalk, OCaml and Delphi and other languages.

    What is JSON?

    JavaScript Object Notation is a lightweight data-interchange format. It is easy for humans to read and write. It is easy for machines to parse and generate. It is based on a subset of the JavaScript Programming Language.

    Need advice about which tool to choose?Ask the StackShare community!

    What companies use Apache Thrift?
    What companies use JSON?
    Manage your open source components, licenses, and vulnerabilities
    Learn More

    Sign up to get full access to all the companiesMake informed product decisions

    What tools integrate with Apache Thrift?
    What tools integrate with JSON?

    Sign up to get full access to all the tool integrationsMake informed product decisions

    Blog Posts

    Aug 28 2019 at 3:10AM

    Segment

    PythonJavaAmazon S3+16
    7
    2632
    What are some alternatives to Apache Thrift and JSON?
    gRPC
    gRPC is a modern open source high performance RPC framework that can run in any environment. It can efficiently connect services in and across data centers with pluggable support for load balancing, tracing, health checking...
    Protobuf
    Protocol buffers are Google's language-neutral, platform-neutral, extensible mechanism for serializing structured data – think XML, but smaller, faster, and simpler.
    REST
    An architectural style for developing web services. A distributed system framework that uses Web protocols and technologies.
    Avro
    It is a row-oriented remote procedure call and data serialization framework developed within Apache's Hadoop project. It uses JSON for defining data types and protocols, and serializes data in a compact binary format.
    GraphQL
    GraphQL is a data query language and runtime designed and used at Facebook to request and deliver data to mobile and web apps since 2012.
    See all alternatives