I know this post has been a while ago, but running into the same problem as the OP and the last couple of days digging in the googles hasn’t got me there either
@hsarret 's response got me part of the way there, but can’t quite piece it together
(I’m on ue5.1)
I’m using HTTP to send graphql queries and need the output to be programatic and in JSON format.
I’m trying to output json in the following format
{
"page_input":
{
"page_num": 1,
"page_size": 100,
"sort_order": "ASC",
"filter_by_inputs":
[
{
"field_name": "unit_state",
"values": ["error", "targeted"]
}
]
}
}
The following what what I have:
// This is the top level dict
TSharedPtr<FJsonObject> VariablesJsonObject = MakeShareable(new FJsonObject);
// This is the page input dict
TSharedPtr<FJsonObject> PageInputJsonObject = MakeShareable(new FJsonObject);
// Add the page_input dict to the variables dict
VariablesJsonObject->SetObjectField("page_input", PageInputJsonObject);
// Add the other fields to the page_input dict
PageInputJsonObject->SetNumberField("page_num", 1);
PageInputJsonObject->SetNumberField("page_size", 100);
PageInputJsonObject->SetStringField("sort_order", "ASC");
// create the filter_by_inputs dict which will needed to be "Added" to the filter_by_inputs Array
TSharedPtr<FJsonObject> FilterByInputsJsonObject = MakeShareable(new FJsonObject);
// Create the filter_by_inputs array
TArray<FJsonObject> FilterByInputsArray;
// Add field to filter_by_inputs dict
FilterByInputsJsonObject->SetStringField("field_name", "op_state");
// Add the dict to the array
FilterByInputsArray.Add(*FilterByInputsJsonObject);
// create the field_values array and add the values to it
TArray<TSharedPtr<FJsonValue>> FieldValuesArray;
FilterByInputsJsonObject->SetArrayField("values", FieldValuesArray );
FieldValuesArray.Add(MakeShareable(new FJsonValueString("error")));
FieldValuesArray.Add(MakeShareable(new FJsonValueString("targeted")));
// Create the json value object to store the dict in
TSharedRef<FJsonValueObject> FilterByInputsJsonValueObject = MakeShareable (new FJsonValueObject(FilterByInputsJsonObject));
// Add the value object that is an array into the page_inputs dict
PageInputJsonObject->SetArrayField("filter_by_inputs", FilterByInputsJsonValueObject);
The error from the IDE (rider) I get, is
cannot convert TSharedRef<FJsonValueObect> to TArray<TSharedPtr<FJsonValue>>
my brain is melting lol. Any help would be greatly appreciated
What would be even more amazing, if there was a generator you could pass a json dict to and it would generate the ue cpp for it haha. (I looked, couldn’t find one )
cheers