Giter Site home page Giter Site logo

abhi16180 / json2struct Goto Github PK

View Code? Open in Web Editor NEW
3.0 1.0 0.0 27 KB

The JSON to Struct Generator is a simple tool written in Go that generates Go struct definitions based on JSON input. It's useful for quickly creating Go struct types that match the structure of JSON data.

License: GNU General Public License v3.0

Go 100.00%

json2struct's Introduction

JSON to Struct Generator

This tool converts JSON data into Go struct definitions.

Overview

The JSON to Struct Generator is a simple tool written in Go that generates Go struct definitions based on JSON input. It's useful for quickly creating Go struct types that match the structure of JSON data.

Features

  • Converts JSON data to Go struct definitions
  • Handles nested structures, arrays, and complex JSON data
  • Copies generated struct definitions to the clipboard

Usage

Clone the repository and run the tool with the following command:

go run main.go <json-file path>

sample.json

{
  "name": "John",
  "age": 30,
  "cars": {
    "car1": "Ford",
    "car2": "BMW",
    "car3": "Fiat",
    "custom": {
      "name": "custom",
      "age": 30,
      "is_student": true,
      "grades": [
        1,
        2,
        3
      ],
      "address": {
        "city": "New York",
        "zip_code": "10001",
        "coordinates": {
          "latitude": 40.7128,
          "longitude": 74.0060
        }
      },
      "friends": [
        {
          "city": "New York",
          "zip_code": "10001"
        }
      ]
    }
  }
}

sample output

type Base struct {
    Name string  `json:"name"`
    Age  float64 `json:"age"`
    Cars Cars    `json:"cars"`
}
type Cars struct {
    Car1   string `json:"car1"`
    Car2   string `json:"car2"`
    Car3   string `json:"car3"`
    Custom Custom `json:"custom"`
}
type Custom struct {
    Age       float64   `json:"age"`
    IsStudent bool      `json:"is_student"`
    Grades    []float64 `json:"grades"`
    Address   Address   `json:"address"`
    Friends   []Friends `json:"friends"`
    Name      string    `json:"name"`
}
type Address struct {
    City        string      `json:"city"`
    ZipCode     string      `json:"zip_code"`
    Coordinates Coordinates `json:"coordinates"`
}
type Friends struct {
    ZipCode string `json:"zip_code"`
    City    string `json:"city"`
}
type Coordinates struct {
    Latitude  float64 `json:"latitude"`
    Longitude float64 `json:"longitude"`
}

json2struct's People

Contributors

abhi16180 avatar

Stargazers

Rakhim Abdullayev avatar kinar avatar Adeep Krishna Keelar avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.