python json string to object
import json
x = '{ "name":"John", "age":30, "city":"New York"}'
y = json.loads(x)
print(y["age"])
python json string to object
import json
x = '{ "name":"John", "age":30, "city":"New York"}'
y = json.loads(x)
print(y["age"])
golang parsing xml
package main
import (
"encoding/json"
"encoding/xml"
"fmt"
)
type Data struct {
XMLName xml.Name `xml:"data" json:"-"`
PersonList []Person `xml:"person" json:"people"`
}
type Person struct {
XMLName xml.Name `xml:"person" json:"-"`
Firstname string `xml:"firstname" json:"firstname"`
Lastname string `xml:"lastname" json:"lastname"`
Address *Address `xml:"address" json:"address,omitempty"`
}
type Address struct {
City string `xml:"city" json:"city,omitempty"`
State string `xml:"state" json:"state,omitempty"`
}
func main() {
rawXmlData := "<data><person><firstname>Nic</firstname><lastname>Raboy</lastname><address><city>San Francisco</city><state>CA</state></address></person><person><firstname>Maria</firstname><lastname>Raboy</lastname></person></data>"
var data Data
xml.Unmarshal([]byte(rawXmlData), &data)
jsonData, _ := json.Marshal(data)
fmt.Println(string(jsonData))
}
read json file python
import json
with open('path_to_file/person.json') as f:
data = json.load(f)
print(data)
flx = json.dumps(data, ensure_ascii=False, indent=4)
print(flx)
python to json
# a Python object (dict):
x = {
"name": "John",
"age": 30,
"city": "New York"
}
# convert into JSON:
y = json.dumps(x)
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us