-
-
Save sago35/8c4ca019d94996e23ae803ff58a18525 to your computer and use it in GitHub Desktop.
TinyGo 0.28 vs encoding/json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"encoding/json" | |
"fmt" | |
"log" | |
) | |
func main() { | |
err := run() | |
if err != nil { | |
log.Fatal(err) | |
} | |
} | |
// https://developer.twitter.com/en/docs/twitter-api/v1/data-dictionary/overview | |
const twitterJSON = ` | |
{ | |
"created_at": "Thu Apr 06 15:24:15 +0000 2017", | |
"id_str": "850006245121695744", | |
"text": "1\/ Today we\u2019re sharing our vision for the future of the Twitter API platform!\nhttps:\/\/t.co\/XweGngmxlP", | |
"user": { | |
"id": 2244994945, | |
"name": "Twitter Dev", | |
"screen_name": "TwitterDev", | |
"location": "Internet", | |
"url": "https:\/\/dev.twitter.com\/", | |
"description": "Your official source for Twitter Platform news, updates & events. Need technical help? Visit https:\/\/twittercommunity.com\/ #TapIntoTwitter" | |
}, | |
"place": { | |
}, | |
"entities": { | |
"hashtags": [ | |
], | |
"urls": [ | |
{ | |
"url": "https:\/\/t.co\/XweGngmxlP", | |
"unwound": { | |
"url": "https:\/\/cards.twitter.com\/cards\/18ce53wgo4h\/3xo1c", | |
"title": "Building the Future of the Twitter API Platform" | |
} | |
} | |
], | |
"user_mentions": [ | |
] | |
} | |
} | |
` | |
func run() error { | |
v := AutoGenerated{} | |
err := json.Unmarshal([]byte(twitterJSON), &v) | |
if err != nil { | |
return err | |
} | |
b2, err := json.Marshal(v) | |
if err != nil { | |
return err | |
} | |
fmt.Printf("%s\n", string(b2)) | |
return nil | |
} | |
// https://mholt.github.io/json-to-go/ | |
type AutoGenerated struct { | |
CreatedAt string `json:"created_at"` | |
IDStr string `json:"id_str"` | |
Text string `json:"text"` | |
User User `json:"user"` | |
Place Place `json:"place"` | |
Entities Entities `json:"entities"` | |
} | |
type User struct { | |
ID int64 `json:"id"` | |
Name string `json:"name"` | |
ScreenName string `json:"screen_name"` | |
Location string `json:"location"` | |
URL string `json:"url"` | |
Description string `json:"description"` | |
} | |
type Place struct { | |
} | |
type Unwound struct { | |
URL string `json:"url"` | |
Title string `json:"title"` | |
} | |
type Urls struct { | |
URL string `json:"url"` | |
Unwound Unwound `json:"unwound"` | |
} | |
type Entities struct { | |
Hashtags []any `json:"hashtags"` | |
Urls []Urls `json:"urls"` | |
UserMentions []any `json:"user_mentions"` | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment