Closed globalwebforce closed 2 years ago
@globalwebforce Hi 👋 If you have the same JSON objects in the different files you can put them into one and the generator will merge them with the imports path. Otherwise, you need to write import path self. In your case, you don't need two JSON objects just merge them into one 👇
{
"id": 1,
"name": "Jane Doe Shop",
"products": [{
"id": 1,
"name": "product-name"
}]
}
Thank you for your response but I still don't get it sorry :( In my case, I have 3 JsonObjects A,B,C that needs JsonObject Z (a very big json data). How can I tell to the 3 JsonObjects to use JsonObject Z (must be required)?
JsonObject Z
{
id: 1
title: "I am Z"
}
JsonObject A
{
id: 1
z : //How?
}
JsonObject B
{
id: 1
z : //How?
}
JsonObject C
{
id: 1
z : //How?
}
You can generate multiple JSON
to one folder by adding a patch. And generator will remove duplicate files. In your case should be like that 👇
Note: by adding a patch you need to be careful. Because the generator reads your all
JSON
objects from the all tracked directory from the top to the bottom. In your case I would recommend thez
JSON
file kept above thea
,b
,c
. But, if alla
,b
, andc
have identicalz
then no matter where and how you sort yourJSON
.{ "__className": "z", "__path": "/lib/models/multi_json", "id": 1 "title": "I am Z" }
{ "__className": "a", "__path": "/lib/models/multi_json", "id": 1 "z": { id: 1 title: "I am Z" } }
{ "__className": "b", "__path": "/lib/models/multi_json", "id": 1 "z": { id: 1 title: "I am Z" } }
{ "__className": "c", "__path": "/lib/models/multi_json", "z": { id: 1 title: "I am Z" } }
// files directory. ./json_models/ |-z.json |-a.json |-b.json |-c.json
@globalwebforce
Oh I get it, I just thought that there could be a shortcut to reference a JsonObect specially if it's very big. Base on your example, you copy-pasted the whole json structure of JsonObject Z to the other JsonObjects. Now I know what I'm doing is right, I can now proceed on my Project, Thank you very much!
@globalwebforce You are welcome. Just remember, when you copy and paste JSON
Z
structure to JSON
A
don't forget change json key as Z
class name in the JSON
A
.
I think this cool trick should be noted in the Readme file.
Is there an existing issue for this?
Current Behavior
Product Model
Shop Model
Expected Behavior
No response
Steps To Reproduce
No response
Version
No response
Relevant JSON syntax
No response
Anything else?
No response