Skip to content
/ jsontime Public
forked from liamylian/jsontime

A json iterator extension that support custom time format

License

Notifications You must be signed in to change notification settings

ilibs/jsontime

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

jsontime

A json iterator extension that support custom time format.

Usage

100% compatibility with standard lib

Replace

import "encoding/json"

json.Marshal(&data)
json.Unmarshal(input, &data)

with

import "github.com/liamylian/jsontime"

var json = jsontime.ConfigWithCustomTimeFormat

json.Marshal(&data)
json.Unmarshal(input, &data)

Example

package main

import(
	"fmt"
	"time"
	"github.com/liamylian/jsontime"
)

var json = jsontime.ConfigWithCustomTimeFormat

type Book struct {
	Id          int           `json:"id"`
	PublishedAt time.Time     `json:"published_at" time_format:"2006-01-02 15:04:05"`
	UpdatedAt   *time.Time    `json:"updated_at" time_format:"sql_date" time_utc:"true"`
	CreatedAt   time.Time     `json:"created_at" time_format:"sql_datetime" time_location:"UTC"`
}

func main() {
	book := Book {
		Id:          1,
		PublishedAt: time.Now(),
		UpdatedAt:   nil,
		CreatedAt:   time.Now(),
	}
	
	bytes, _ := json.Marshal(book)
	fmt.Printf("%s", bytes)
}

About

A json iterator extension that support custom time format

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 100.0%