Golang YAML with nested properties to JSON - json

I'm trying to parse some YAML from a file and convert each item to a flat JSON object.
I'm having some issues with datasets where there are multiple / nested objects.
I'm failing to unmarshal multiple items per file.
I'm unsure how to get nested properties such has item -> description -> en
When I run the following code I get the error.
cannot unmarshal !!map into []item.Item
I think I've got to look into sub-types within my structure, but I can't seem to get anything to work.
Any help would be appreciated.
Code:
import (
"gopkg.in/yaml.v2"
"io/ioutil"
)
func parseItemYaml() {
filePath := "./typeIDs.yaml"
yamlFile, err := ioutil.ReadFile(filePath)
if err != nil {
log.Printf("yamlFile.Get err #%v ", err)
}
itemData := map[int][]Item{}
err = yaml.Unmarshal(yamlFile, &itemData)
if err != nil {
panic(err)
}
// Then convert to JSON
// Eventual persistance
}
Item Structure:
type Item struct {
ID int
Name string `yaml:"name"`
Description string `yaml:"description"`
GroupID int `yaml:"groupID"`
IconID int `yaml:"iconID"`
GraphicID int `yaml:"graphicID"`
MarketGroupID int `yaml:"marketGroupID"`
Mass float64 `yaml:"mass"`
Published bool `yaml:"published"`
Volume float64 `yaml:"volume"`
}
Desired JSON format:
{
"ID":1563,
"Description":"Radiates an omnidirectional pulse from the ship that causes EM damage to surrounding vessels.",
"GroupID":72,
"IconID":112,
"GraphicID":72,
"MarketGroupID":382,
"Mass":10.0,
"Published":true,
"Volume":12.5
},
{...},
{...}
Data Subset:
1563:
description:
de: Ein ungerichteter Rundum-Impuls der vom Schiff ausgestrahlt wird und bei
umliegenden Schiffen EM-Schaden verursacht.
en: Radiates an omnidirectional pulse from the ship that causes EM damage
to surrounding vessels.
fr: Émet une impulsion omnidirectionelle qui part du vaisseau et provoque
des dégâts électromagnétiques à tous les vaisseaux situés à proximité.
ja: 全方位にパルスを放射し、周囲の艦にEMダメージを与える。
ru: Испускает сильный всенаправленный импульс, наносящий электромагнитный
ущерб всем объектам, окружающим корабль.
zh: 从舰船上发射一个全向脉冲,对周围船只造成电磁伤害。
graphicID: 2032
groupID: 72
iconID: 112
marketGroupID: 382
mass: 10.0
name:
de: Small EMP Smartbomb I
en: Small EMP Smartbomb I
fr: Petite bombe de proximité à IEM I
ja: 小型EMPスマートボムI
ru: Small EMP Smartbomb I
zh: 小型EMP立体炸弹 I
portionSize: 1
published: true
radius: 1000.0
volume: 12.5
1564:
basePrice: 650000.0
groupID: 152
iconID: 112
marketGroupID: 341
name:
de: Small EMP Smartbomb I Blueprint
en: Small EMP Smartbomb I Blueprint
fr: Plan de construction Petite bombe de proximité à IEM I
ja: 小型EMPスマートボムIブループリント
ru: Small EMP Smartbomb I Blueprint
zh: 小型EMP立体炸弹蓝图 I
portionSize: 1
published: true
volume: 0.01
1565:
description:
de: Ein ungerichteter Rundum-Impuls der vom Schiff ausgestrahlt wird und bei
umliegenden Schiffen EM-Schaden verursacht.
en: Radiates an omnidirectional pulse from the ship that causes EM damage
to surrounding vessels.
fr: Émet une impulsion omnidirectionelle qui part du vaisseau et provoque
des dégâts électromagnétiques à tous les vaisseaux situés à proximité.
ja: 全方位にパルスを放射し、周囲の艦にEMダメージを与える。
ru: Испускает сильный всенаправленный импульс, наносящий электромагнитный
ущерб всем объектам, окружающим корабль.
zh: 从舰船上发射一个全向脉冲,对周围船只造成电磁伤害。
graphicID: 2032
groupID: 72
iconID: 112
marketGroupID: 382
mass: 40.0
name:
de: Small EMP Smartbomb II
en: Small EMP Smartbomb II
fr: Petite bombe de proximité à IEM II
ja: 小型EMPスマートボムII
ru: Small EMP Smartbomb II
zh: 小型EMP立体炸弹 II
portionSize: 1
published: true
radius: 1000.0
volume: 5.0

Make structs e.g. like this:
type Language struct {
De string `yaml:de`
En string `yaml:en`
Fr string `yaml:fr`
Ja string `yaml:ja`
Ru string `yaml:ru`
Zh string `yaml:zh`
}
type Item struct {
Description Language `yaml:description`
GroupID int `yaml:"groupID"`
IconID int `yaml:"iconID"`
GraphicID int `yaml:"graphicID"`
MarketGroupID int `yaml:"marketGroupID"`
Mass float64 `yaml:"mass"`
Name Language `yaml:name`
Published bool `yaml:"published"`
Volume float64 `yaml:"volume"`
}
Also, as far as I see, it should be map[int]Item{} and not map[int][]Item{}.

Related

Failure in Deserialization of File (NewtonSoft.JSON & VB.NET) [duplicate]

This question already has answers here:
How can I parse a JSON string that would cause illegal C# identifiers?
(3 answers)
Cannot deserialize the JSON array (e.g. [1,2,3]) into type ' ' because type requires JSON object (e.g. {"name":"value"}) to deserialize correctly
(6 answers)
Closed 1 year ago.
I have a small test file I'm trying to work with to deserialize the data into a model. I've already this using tokens in NewtonSoft.JSON but would rather do this properly with a model.
Example JSON
[
{
"faction": "Britain",
"id": "aa_barrage",
"image": "aa_barrage.png",
"import_id": "02",
"kredits": 1,
"rarity": "Standard",
"set": "Base",
"text": {
"de-DE": "Die gewählte Lufteinheit muss sich zurückziehen. Gibt deinem HQ +2 Verteidigung.",
"en-EN": "Target air unit must retreat. Give your HQ +2 defense.",
"es-ES": "La unidad aérea seleccionada debe retirarse. Otorga un +2 de defensa a tu cuartel general.",
"fr-FR": "L'unité aérienne visée doit battre en retraite. Confère +2 de défense à votre QG",
"it-IT": "L'unità aerea bersaglio deve Ritirarsi. Dai al tuo QG +2 difesa.",
"pl-PL": "Wybrana jednostka powietrzna musi się wycofać. Zapewnij swojemu sztabowi +2 do obrony.",
"pt-BR": "A unidade aérea na mira deve recuar. Dê +2 de defesa ao seu QG.",
"ru-RU": "Выбранный воздушный отряд должен отступить. Ваш штаб получает +2 к защите.",
"zh-Hans": "使一个空军撤退,你的总部获得 +2 防御力。",
"zh-Hant": "使一個空軍撤退,你的總部獲得 +2 防禦力。"
},
"title": {
"de-DE": "FLAK-SPERRFEUER",
"en-EN": "AA BARRAGE",
"es-ES": "BOMBARDEO AA",
"fr-FR": "BARRAGE AA",
"it-IT": "CONTRAEREA",
"pl-PL": "ZAPORA PRZECIWLOTNICZA",
"pt-BR": "BARRAGEM AA",
"ru-RU": "ЗЕНИТНЫЙ ОГОНЬ",
"zh-Hans": "防空弹幕",
"zh-Hant": "防空彈幕"
},
"type": "order"
},
{
"faction": "Britain",
"id": "active_sonar",
"image": "active_sonar.png",
"import_id": "fy",
"kredits": 0,
"rarity": "Elite",
"set": "OnlySpawnable",
"text": {
"de-DE": "Setzt alle feindlichen Einheiten fest. Karten in der gegnerischen Hand kosten 3 mehr.",
"en-EN": "Pin all enemy units. Increase cost of all cards in enemy hand by 3.",
"es-ES": "Inmoviliza todas las unidades enemigas. Las cartas en la mano del enemigo cuestan 3 más.",
"fr-FR": "Immobilise toutes les unités ennemies. Les cartes dans la main de l'ennemi coûtent 3 de plus.",
"it-IT": "Blocca tutte le unità nemiche. Aumenta di 3 il costo delle carte nella mano del nemico.",
"pl-PL": "Przyszpil wszystkie wrogie jednostki. Koszt kart w ręce przeciwnika wzrasta o 3.",
"pt-BR": "Imobilize todas as unidades inimigas. Todas as cartas na mão do inimigo custam mais 3.",
"ru-RU": "Блокирует все вражеские отряды. Карты в руке противника стоят на 3 больше.",
"zh-Hans": "压制敌方所有单位。对手所有手牌花费 +3。",
"zh-Hant": "壓制敵方所有單位。對手所有手牌花費 +3。"
},
"title": {
"de-DE": "AKTIVES SONAR",
"en-EN": "ACTIVE SONAR",
"es-ES": "SONAR ACTIVO",
"fr-FR": "SONAR ACTIF",
"it-IT": "SONAR ATTIVO",
"pl-PL": "AKTYWNY SONAR",
"pt-BR": "SONAR ATIVO",
"ru-RU": "АКТИВНЫЙ СОНАР",
"zh-Hans": "主动声呐",
"zh-Hant": "主動聲納"
},
"type": "order"
}
]
The current code I have for this is the following:
Module Program
Sub Main(args As String())
dim json As string = File.ReadAllText("C:\Temp\cards.json")
dim result As cards = JsonConvert.DeserializeObject(Of cards)(json)
End Sub
End Module
Public Class cards
public property cards as list(of card)
End Class
Public Class card
public property faction as string
public property id as string
public property image as string
public property import_id as string
public property kredits as integer
public property rarity as string
<JsonProperty("set")>
public property cardset as string
public property type as string
End Class
I can deserialize just one of these on its own, however when I try and deserialize with both it fails due to the following:
Newtonsoft.Json.JsonSerializationException: Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 'json_deserialize_test.cards' because the type requires a JSON object (e.g. {"name":"value"}) to deserialize correctly.
To fix this error either change the JSON to a JSON object (e.g. {"name":"value"}) or change the deserialized type to an array or a type that implements a collection interface (e.g. ICollection, IList) like List<T> that can be deserialized from a JSON array. JsonArrayAttribute can also be added to the type to force it to deserialize from a JSON array.
I have tried changing my deserialization to:
dim result As cards = JsonConvert.DeserializeObject(Of List(Of cards))(json)
but to no available, something that was mentioned in another question, can someone point me in the right direction here please, I feel like I've been looking at it too long and need another pair of eyes.

Rebuild JSON string to a different structure, parsing specific fields

I receive a JSON like this
{
"raw_content":"very long string"
"mode":"ML",
"user_id":"4000008367",
"user_description":"John Doe",
"model":3,
"dest_contact":"test#email.it",
"order_details":[
"ART.: 214883 PELL GRANI 9 ESPR.BAR SKGR 1000 SGOC.: 1000 GR\nVS.ART: 305920132 COMPOS. PALLET\n36 COLLI PEZ.RA: 6 TOT.PEZZI: 216 B: 12 T: 6\nEU C.L.: 24,230\nCO SCAP- : 16,500 CA SCAP- : 15,000 CO SCCP- : 0,000\nCO SAGV- : 0,00000\nC.N. : 17,200SCAD.MIN.: 25/01/22\nCONDIZIONI PAGAMENTO : 60GG B.B. DT RIC FT FINEMESE ART62\n",
"ART.: 287047 PELLINI BIO100%ARABICALTGR 250 SGOC.: 250 GR\nVS.ART: 315860176 COMPOS. PALLET\n36 COLLI PEZ.RA: 6 TOT.PEZZI: 216 B: 12 T: 3\nEU C.L.: 8,380\nCO SCAP- : 16,500 PR SCAP- : 15,000 CO SCCP- : 0,000\nCO SAGV- : 0,00000\nC.N. : 5,950SCAD.MIN.: 25/01/22\nCONDIZIONI PAGAMENTO : 60GG B.B. DT RIC FT FINEMESE ART62\n",
"ART.: 3137837 CAFFE PELLINI TOP LTGR 250 SGOC.: 250 GR\nVS.ART: 315850175 COMPOS. PALLET\n30 COLLI PEZ.RA: 12 TOT.PEZZI: 360 B: 6 T: 5\nEU C.L.: 6,810\nCO SCAP- : 16,500 PR SCAP- : 12,000 CO SCCP- : 0,000\nCO SAGV- : 0,00000\nC.N. : 5,000SCAD.MIN.: 18/08/21\nCONDIZIONI PAGAMENTO : 60GG B.B. DT RIC FT FINEMESE ART62\n",
"ART.: 7748220 ESPRES.SUP.TRADIZ. MOKPKGR 500 SGOC.: 500 GR\nVS.ART: 315930114 COMPOS. PALLET\n80 COLLI PEZ.RA: 10 TOT.PEZZI: 800 B: 10 T: 6\nEU C.L.: 7,580\nCO SCAP- : 16,500 PR SCAP- : 27,750 CO SCCP- : 0,000\nCO SAGV- : 0,00000\nC.N. : 4,570SCAD.MIN.: 25/01/22\nCONDIZIONI PAGAMENTO : 60GG B.B. DT RIC FT FINEMESE ART62\n"
],
"order_footer":"\nPALLET DA CM. 80X120\nT O T A L E C O L L I 182\n\n- EX D.P.R. 322 - 18/05/82 NON SI ACCETTANO TERMINI MINIMI DI\nCONSERVAZIONE INFERIORI A QUELLI INDICATI\n- CONSEGNA FRANCO BANCHINA, PALLET MONOPRODOTTO\nCOME DA PALLETTIZZAZIONE SPECIFICATA\nCONDIZIONI DI PAGAMENTO : COME DA ACCORDI\n"
}
and I want to reorder it to this
{
id: "32839ds8a32jjdas93193snkkk32jhds-k2j1", // generated, see my implementation
rawContent: "very long string",
parsedContent: {"mode":"ML", "user_id":"4000008367", "user_description":"John Doe", "order_details":[ "....." ], ... } // basically all the fields except raw content
}
How can I do this? I'm trying to work it with maps:
var output map[string]interface{}
var message processing.Document // message is of type struct {ID string, Raw string, Parsed string}
err = json.Unmarshal([]byte(doc), &output)
if err != nil {
// error handling
}
message.ParsedContent = "{"
for key, data := range output {
if key == "raw_content" {
hash := md5.Sum([]byte(data.(string)))
message.ID = hex.EncodeToString(hash[:])
message.RawContent = base64.RawStdEncoding.EncodeToString([]byte(data.(string)))
} else {
temp := fmt.Sprintf("\"%s\": \"%s\", ", key, data)
message.ParsedContent = message.ParsedContent + temp
}
}
message.ParsedContent = message.ParsedContent + "}"
msg, err := json.Marshal(message)
if err != nil {
// error handling
}
fmt.Println(string(msg))
There's a few problem with this. If it was only strings it would be ok, but there are integers and the sprintf doesn't work (the output I get, for example on the field "model" is "model": "%!s(float64=3)". I could do an if key == model and parse it as an int, but as I said the fields are not always the same and there are other integers that sometimes are there and sometimes are not there.
Also, the field "order_footer" has escaped new lines which are somehow deleted in my parsing, and this breaks the validity of the resulting JSON.
How can I solve this issues?
EDIT: As suggested, hand-parsing JSON is a bad idea. I could parse it into a struct, the field "model" actually tells me which struct to use. The struct for "model": 3 for example is:
type MOD3 struct {
Raw string `json:"raw_content"`
Mode string `json:"mode"`
UserID string `json:"user_id"`
UserDes string `json:"user_description"`
Model int `json:"model"`
Heading string `json:"legal_heading"`
DestContact string `json:"dest_contact"`
VendorID string `json:"vendor_id"`
VendorLegal string `json:"vendor_legal"`
OrderID string `json:"order_id"`
OrderDate int64 `json:"order_date"`
OrderReference string `json:"order_reference"`
DeliveryDate int64 `json:"delivery_date"`
OrderDestination string `json:"order_destination"`
OrderDestinationAddress string `json:"order_destination_address"`
Items []string `json:"order_details"`
OrderFooter string `json:"order_footer"`
}
At this point, how can I parse specific fields to the output format?
You should never, ever, ever try to generate JSON by hand. The steps should be:
Get JSON and parse it in a model object.
Create a copy of the model object with all the changes you want.
Convert the copied model object to JSON.
You don't know enough about JSON to modify it on the fly. I know enough, and the only reasonable way is complete parsing, and writing back the complete changes.

Download a html report, with an image inside, from a shiny app hosted in shinyapps.io

I want to download a html report with an image (.jpg) printed on it. It works just fine locally with the following code:
---
title: "Informe de ensayo"
output: html_document
params:
n: NA
---
```{r, echo = FALSE}
img(src='http://aios.pe/storage/app/media/COMACSA/header.png', align = "center")
```
But when I uploaded the app into shinyapps.io, I couldn't download the report anymore.
The downloaded file looks like this:
And the LOG shows this:
Warning in grep("\n", x) :
Warning in grep("^(---|\\.\\.\\.)\\s*$", lines) :
processing file: reporte.Rmd
string de entrada 43 es inválida en este locale
string de entrada 43 es inválida en este locale
string de entrada 43 es inválida en este locale
string de entrada 43 es inválida en este locale
Warning in grepl(chunk.end, lines) :
|
| | 0%
|
|........... | 17%
Warning in grepl(chunk.begin, lines) :
ordinary text without R code
List of 1
|
|...................... | 33%
$ echo: logi FALSE
label: unnamed-chunk-1 (with options)
|
|........................................... | 67%
|
|................................ | 50%
label: unnamed-chunk-2 (with options)
ordinary text without R code
$ echo : logi FALSE
List of 2
$ results: chr "asis"
|
|...................................................... | 83%
inline R code fragments
Quitting from lines 39-46 (reporte.Rmd)
Warning: Error in nchar: invalid multibyte string, element 1
[No stack trace available]
Thanks!

Is there a more elegant way to pass a big object variable to jq?

I have the following JSON input to transform (an array of hundreds of similar objects):
[{
"Nmarch\u00e9": "2013-90006",
"SIRETMandataire": null,
"LibelleEntiteMandataire": "R\u00e9gion Bretagne",
"SIRETAcheteur": null,
"LibelleAcheteur": null,
"Nature": null,
"Objet": "PBF Formation qualifiante 2013 Monteur en construction bois lot 4",
"CodeCPV": null,
"Type ": "Services",
"Procedure": "MAPA - art 30 - au dessus des seuils",
"CodePostalCommuneExecution": 35000.0,
"NomCommuneExecution": "Rennes",
"CodeINSEEExecution": null,
"GranulariteINSEEExecution": null,
"MillesimeMandatement": 2013,
"DateNotification": "2013-10-01",
"Montant mandate TTC": 245526,
"Montant mandate HT": null,
"Montant attribue TTC": 245526,
"Montant attribue HT": null,
"Date de cloture": null,
"Duree": null,
"SIRETContractant": 300599123,
"DenominationSociale": "AFPA DIRECTION REGIONALE BRETAGNE",
"Role": "Titulaire",
"CodePostal": 35208,
"Dpt ID ": 35,
"D\u00e9partement": "Ille-et-Vilaine",
"Commune": "RENNES",
"Taille": "10 000 et plus",
"Taille des entreprises par categorie officielle": "Grande entreprise",
"Code NAF": 8559,
"Libelle NAF": "ENSEIGNEMENT",
"Libelle SBA": "Administration publique\/enseignement",
"Libelle CCI": "Tertiaire non marchand",
"geolocalisation": null
}
]
In Procedure, I have a lot of invalid values that I need to replace through a value mapping. I consequently want to feed a JSON object to my jq transform, with the invalid values as keys and the right values as values:
{
"MAPA - art 28": "Procédure adaptée",
"MAPA - art 30 - au dessus des seuils": "Procédure adaptée",
"MAPA - art 30 - en dessous des seuils": "Procédure adaptée",
"Proc. adaptée/allégée (art.28et30)": "Procédure adaptée",
"Procédure adaptée (MAPA)": "Procédure adaptée",
"Appel d'offre ouvert": "Appel d'offres ouvert",
"appel d'offres ouvert": "Appel d'offres ouvert",
"Appel d'offre ouvert (art.33)": "Appel d'offres ouvert",
"Appel d'offre restreint": "Appel d'offres restreint",
"Achat direct": "Marché négocié sans publicité ni mise en concurrence préalable",
"Négocié avec pub (art.35I)": "Procédure négociée avec mise en concurrence préalable",
"Procédure négociée après pub": "Procédure négociée avec mise en concurrence préalable",
"Procédure négociée après pub.": "Procédure négociée avec mise en concurrence préalable",
"Procédure négociée sans pub": "Marché négocié sans publicité ni mise en concurrence préalable",
"Procédure négociée sans pub.": "Marché négocié sans publicité ni mise en concurrence préalable",
"Marché négocié": "Marché négocié sans publicité ni mise en concurrence préalable",
"marché négocié": "Marché négocié sans publicité ni mise en concurrence préalable",
"Marché negocié": "Marché négocié sans publicité ni mise en concurrence préalable"
}
I wanted to declare this object in my jq transform file, but I didn't see how to use the bla as var syntax to declare a variable with foreign data (ideally I'd like to declare it as a file). I consequently ended up using the --argjson command line parameter.
This works (I get JSON output with replaced values), but I wish I could have a cleaner command and make it more maintainable:
cat temp.json | jq --argjson procedures '{"MAPA - art 28":"Procédure adaptée","MAPA - art 30 - au dessus des seuils":"Procédure adaptée","MAPA - art 30 - en dessous des seuils":"Procédure adaptée","Proc. adaptée/allégée (art.28et30)":"Procédure adaptée","Procédure adaptée (MAPA)":"Procédure adaptée","Appel d\u0027offre ouvert":"Appel d\u0027offres ouvert","appel d\u0027offres ouvert":"Appel d\u0027offres ouvert","Appel d\u0027offre ouvert (art.33)":"Appel d\u0027offres ouvert","Appel d\u0027offre restreint":"Appel d\u0027offres restreint","Achat direct":"Marché négocié sans publicité ni mise en concurrence préalable","Négocié avec pub (art.35I)":"Procédure négociée avec mise en concurrence préalable","Procédure négociée après pub":"Procédure négociée avec mise en concurrence préalable","Procédure négociée après pub.":"Procédure négociée avec mise en concurrence préalable","Procédure négociée sans pub":"Marché négocié sans publicité ni mise en concurrence préalable","Procédure négociée sans pub.":"Marché négocié sans publicité ni mise en concurrence préalable","Marché négocié":"Marché négocié sans publicité ni mise en concurrence préalable","marché négocié":"Marché négocié sans publicité ni mise en concurrence préalable","Marché negocié":"Marché négocié sans publicité ni mise en concurrence préalable"}' -f jq-filter.jq
For your information, here is jq-filter.jq:
{
"$schema": "../../schémas/json/paquet.json",
"marches" : [.[] | {
id: ."Nmarché",
acheteur: {
id: .SIRETMandataire,
nom: .LibelleEntiteMandataire
},
nature: .Nature,
objet: .Objet,
codeCPV: .CodeCPV,
procedure: $procedures[.Procedure],
lieuExecution: {
code: ( .CodeINSEEExecution //.CodePostalCommuneExecution),
nom: .NomCommuneExecution,
typeCode: (if .CodeINSEEExecution != null then "Code commune" elif .CodePostalCommuneExecution != null then "Code postal" else null end)
},
dateNotification: .DateNotification,
montant: ."Montant Attribue HT",
dureeMois: null,
titulaires: {
id: .SIRETContractant,
denominationSociale: .DenominationSociale
}
}
]
}
Is there a reason you can't use --slurpfile or --argfile ?
--slurpfile variable-name filename:
This option reads all the JSON texts in the named file and binds an array of the parsed JSON values to the given global variable. If you run jq with --argfile foo bar, then $foo is available in the program and has an array whose elements correspond to the texts in the file named bar.
--argfile variable-name filename:
Do not use. Use --slurpfile instead.
(This option is like --slurpfile, but when the file has just one text, then that is used, else an array of texts is used as in --slurpfile.)
Assuming you put your mapping into procedures.json and you change your filter a bit as so:
procedure: $procedures[0][.Procedure],
then you can use --slurpfile:
$ jq --slurpfile procedures procedures.json -f jq-filter.jq temp.json
or you use --argfile (although the docs say not to)
$ jq --argfile procedures procedures.json -f jq-filter.jq temp.json
without any other change to your code.

How can I convert a json in geojson format?

I have seen other similar questions and with good answers, only that the interntarlo in my program tells me error, I may be wrong, the process is as follows. And I think that is correct.
from sys import argv
from os.path import exists
import json
jdata({"metadata":{"resultset":
{"offset":1,"count":125210,"limit":25}},"results":
[{"elevation":139,"mindate":"1948-01-01","maxdate":"2014-01-
01","latitude":31.5702,"name":"ABBEVILLE, AL US","datacoverage":0.8813,"id":"COOP:010008","elevationUnit":"METERS","longitude":-85.2482},{"elevation":249.3,"mindate":"1938-01-01","maxdate":"2015-11-01","latitude":34.2553,"name":"ADDISON, AL US","datacoverage":0.5059,"id":"COOP:010063","elevationUnit":"METERS","longitude":-87.1814},{"elevation":302.1,"mindate":"1940-05-01","maxdate":"1962-03-01","latitude":34.41667,"name":"ADDISON CENTRAL TOWER, AL US","datacoverage":0.9658,"id":"COOP:010071","elevationUnit":"METERS","longitude":-87.31667},{"elevation":172.2,"mindate":"1995-04-01","maxdate":"2015-11-01","latitude":33.17833,"name":"ALABASTER SHELBY CO AIRPORT, AL US","datacoverage":0.8064,"id":"COOP:010116","elevationUnit":"METERS","longitude":-86.78167},{"elevation":183.8,"mindate":"1949-01-01","maxdate":"1949-12-01","latitude":34.6891,"name":"BELLE MINA, AL US","datacoverage":1,"id":"COOP:010117","elevationUnit":"METERS","longitude":-86.8819},{"elevation":34.1,"mindate":"1935-05-01","maxdate":"1936-11-01","latitude":31.13333,"name":"ALAGA, AL US","datacoverage":0.2624,"id":"COOP:010125","elevationUnit":"METERS","longitude":-85.06667},{"elevation":53.3,"mindate":"1940-11-01","maxdate":"2014-12-01","latitude":32.2322,"name":"ALBERTA, AL US","datacoverage":0.9888,"id":"COOP:010140","elevationUnit":"METERS","longitude":-87.4104},{"elevation":348.1,"mindate":"1931-01-01","maxdate":"1977-06-01","latitude":34.23333,"name":"ALBERTVILLE, AL US","datacoverage":0.9535,"id":"COOP:010148","elevationUnit":"METERS","longitude":-86.16667},{"elevation":195.1,"mindate":"1969-10-01","maxdate":"2015-11-01","latitude":32.9452,"name":"ALEXANDER CITY, AL US","datacoverage":0.9946,"id":"COOP:010160","elevationUnit":"METERS","longitude":-85.948},{"elevation":200.9,"mindate":"1942-11-01","maxdate":"1969-10-01","latitude":32.98333,"name":"ALEXANDER CITY 6 NE, AL US","datacoverage":0.9629,"id":"COOP:010163","elevationUnit":"METERS","longitude":-85.86667},{"elevation":59.4,"mindate":"1940-01-01","maxdate":"2015-11-01","latitude":33.1272,"name":"ALICEVILLE, AL US","datacoverage":0.9144,"id":"COOP:010178","elevationUnit":"METERS","longitude":-88.155},{"elevation":50.3,"mindate":"1980-05-01","maxdate":"2015-11-01","latitude":33.21,"name":"ALICEVILLE L AND D, AL US","datacoverage":0.9883,"id":"COOP:010184","elevationUnit":"METERS","longitude":-88.2878},{"elevation":76.2,"mindate":"1938-01-01","maxdate":"2015-11-01","latitude":31.3071,"name":"ANDALUSIA 3 W, AL US","datacoverage":0.9744,"id":"COOP:010252","elevationUnit":"METERS","longitude":-86.5226},{"elevation":208.8,"mindate":"2004-07-01","maxdate":"2015-11-01","latitude":34.9093,"name":"ANDERSON, AL US","datacoverage":1,"id":"COOP:010260","elevationUnit":"METERS","longitude":-87.2746},{"elevation":220.1,"mindate":"1948-01-01","maxdate":"1949-03-01","latitude":33.66667,"name":"ANNISTON, AL US","datacoverage":1,"id":"COOP:010267","elevationUnit":"METERS","longitude":-85.83333},{"elevation":181.1,"mindate":"1948-01-01","maxdate":"2015-11-01","latitude":33.5872,"name":"ANNISTON METROPOLITAN AIRPORT, AL US","datacoverage":0.9816,"id":"COOP:010272","elevationUnit":"METERS","longitude":-85.8556},{"elevation":227.1,"mindate":"1938-01-01","maxdate":"1983-10-01","latitude":34.06667,"name":"ARLEY 1 S, AL US","datacoverage":0.9691,"id":"COOP:010338","elevationUnit":"METERS","longitude":-87.23333},{"elevation":311.5,"mindate":"1948-01-01","maxdate":"2013-11-01","latitude":33.2941,"name":"ASHLAND, AL US","datacoverage":0.8872,"id":"COOP:010369","elevationUnit":"METERS","longitude":-85.7788},{"elevation":180.1,"mindate":"1941-06-01","maxdate":"1973-06-01","latitude":33.85,"name":"ASHVILLE, AL US","datacoverage":0.9429,"id":"COOP:010377","elevationUnit":"METERS","longitude":-86.33333},{"elevation":210,"mindate":"1948-01-01","maxdate":"2015-11-01","latitude":34.7752,"name":"ATHENS, AL US","datacoverage":0.5632,"id":"COOP:010390","elevationUnit":"METERS","longitude":-86.9508},{"elevation":219.5,"mindate":"1955-10-01","maxdate":"1991-07-01","latitude":34.8,"name":"ATHENS 2, AL US","datacoverage":0.9442,"id":"COOP:010395","elevationUnit":"METERS","longitude":-86.98333},{"elevation":220.1,"mindate":"1958-05-01","maxdate":"1958-06-01","latitude":34.8,"name":"ATHENS COURTHOUSE, AL US","datacoverage":0.998,"id":"COOP:010398","elevationUnit":"METERS","longitude":-86.96667},{"elevation":91.4,"mindate":"1940-01-01","maxdate":"2015-11-01","latitude":31.182,"name":"ATMORE, AL US","datacoverage":0.7103,"id":"COOP:010402","elevationUnit":"METERS","longitude":-87.439},{"elevation":67.1,"mindate":"1965-01-01","maxdate":"1982-10-01","latitude":31.01667,"name":"ATMORE, AL US","datacoverage":0.967,"id":"COOP:010407","elevationUnit":"METERS","longitude":-87.51667},{"elevation":223.1,"mindate":"1931-01-01","maxdate":"1970-12-01","latitude":32.6,"name":"AUBURN, AL US","datacoverage":0.9917,"id":"COOP:010422","elevationUnit":"METERS","longitude":-85.5}]}
script, in_file, out_file = argv
data = json.loads(jdata)
geo_map = {"type":"FeatureCollection"}
It is here that will not let me continue
geojson = {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry" : {
"type": "Point",
"coordinates": [point["lon"], point["lat"]],
},
"properties" : {
"mindate":[],
"maxdate":[],
"name":[],
"datacoverage":[],
"id":[],
"elevationUnit":[],
}
for Point in data]
output = open(out_file, 'w')
json.dump(geojson, output)
print geojson
My English is not very good, i hope you understand and can help me please.