You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -108,9 +108,41 @@ class GeneratedStruct(TypedDict):
108
108
string_key: str
109
109
```
110
110
111
-
## Defaults
111
+
#### Julia
112
112
113
-
If json2struct isn't able to determine the type of a given element, it tries to convert it to the closest type possible.
113
+
```sh
114
+
# example.json
115
+
{
116
+
"number_key": 1,
117
+
"string_key": "json2struct",
118
+
"boolean_key": true,
119
+
"array_key": [42],
120
+
"map_key": { "key": "value" }
121
+
}
122
+
123
+
$ npx json2struct example.json example.jl --language julia
124
+
```
125
+
126
+
Writes the following to the output file:
127
+
128
+
```julia
129
+
# example.jl
130
+
struct SubStruct1
131
+
key::String
132
+
end
133
+
134
+
struct GeneratedStruct
135
+
array_key::Array{Int64}
136
+
boolean_key::Bool
137
+
map_key::SubStruct1
138
+
number_key::Int64
139
+
string_key::String
140
+
end
141
+
```
142
+
143
+
## Unknown values
144
+
145
+
If json2struct isn't able to determine the type of a given element, it tries to convert it to the closest type possible. In most languages this will be the `Any` type of the language.
114
146
115
147
### Empty arrays
116
148
@@ -128,6 +160,12 @@ Array<unknown>;
128
160
List[Any]
129
161
```
130
162
163
+
#### Julia
164
+
165
+
```julia
166
+
Array{Any}
167
+
```
168
+
131
169
### Empty hashmaps
132
170
133
171
Hashmaps without keys will be converted to:
@@ -144,10 +182,18 @@ Record<string, unknown>;
144
182
Dict[Any, Any]
145
183
```
146
184
185
+
#### Julia
186
+
187
+
```
188
+
Dict{Any,Any}
189
+
```
190
+
147
191
## Notes
148
192
149
193
As said earlier the aim of this tool is to be used as a helper when writing type definitions, for that reason json2struct tries not to augment the output in any way.
150
194
151
195
One such example is not flattening the values of maps. In some cases it might make sense to flatten `[{ "a": 1 }, { "b": 1 }]` into `type GeneratedStruct = [{ a?: number; b?: number }];`. But in most cases flattening of maps requires having preexisting knowledge about the data that should be expected. For that reason json2struct prefers to let the user augment the type definition after, instead of imposing it's views on the user.
152
196
153
197
For the same reason json2struct does not take into account whether a key is actually valid in the given language.
198
+
199
+
Since this project is mostly meant to be a way for me to familiarize myself with different langauges, the types might not be the most optimal.
0 commit comments