I am trying to make following JSON in R:
test_json <- '{
"PropertyValues": [{"PropertyDef": 100,
"TypedValue": {
"DataType": 9,
"HasValue": false,
"Value": null,
"Lookup": {
"Deleted": false,
"DisplayValue": null,
"Hidden": false,
"Item": 1,
"Version": -1
},
"Lookups": null,
"DisplayValue": null,
"SortingKey": null,
"SerializedValue": null
}
},
{
"PropertyDef": 0,
"TypedValue": {
"DataType": 1,
"HasValue": false,
"Value": "my test document",
"Lookup": null,
"Lookups": null,
"DisplayValue": null,
"SortingKey": null,
"SerializedValue": null
}
}
],
"Files": [
{
"UploadID": 1,
"Title": null,
"Extension": "txt",
"Size": 27
}
]
}'
This is my try to make above JSON from list object and using jsonlite
package:
create_object <- function(){
json_query <- list(
PropertyValues = list(
PropertyDef = 100,
TypedValue = list(
DataType = 9,
HasValue = FALSE,
Value = NA,
Lookup = list(
Deleted = FALSE,
DisplayValue = NA,
Hidden = FALSE,
Item = 6,
Version = -1
),
Lookups = NA,
DisplayValue = NA,
SortingKey = NA,
SerializedValue = NA
),
PropertyDef = 0,
TypedValue = list(
DataType = 1,
HasValue = FALSE,
Value = "090216ba8014f3be",
Lookup = NA,
Lookups = NA,
DisplayValue = NA,
SortingKey = NA,
SerializedValue = NA
)
),
Files = list(
UploadID = 11,
Title = "090216ba8014f3be",
Extension = "pdf",
Size = 72284
)
)
json_query <- toJSON(json_query, pretty = TRUE, auto_unbox = TRUE)
json_query <- gsub("\\.1", "", json_query)
}
test_json_q <- create_object()
jsonlite::validate(test_json_q)
but this 2 JSON objects are not identical:
identical(test_json, test_json_q)
As I see it the problem is that first JSON object has []
inside {}
, but I don't know how to overcome this issue.