Support
Quality
Security
License
Reuse
kandi's functional review helps you automatically verify the functionalities of the libraries and avoid rework.
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample Here
Get all kandi verified functions for this library.
Performance comparison of a set of event bus implementations (Java)
QUESTION
Build JSON content in R according Google Cloud Pub Sub message format
Asked 2022-Apr-16 at 09:59In R, I want to build json content according this Google Cloud Pub Sub message format: https://cloud.google.com/pubsub/docs/reference/rest/v1/PubsubMessage
It have to respect :
{
"data": string,
"attributes": {
string: string,
...
},
"messageId": string,
"publishTime": string,
"orderingKey": string
}
The message built will be readed from this Python code:
def pubsub_read(data, context):
'''This function is executed from a Cloud Pub/Sub'''
message = base64.b64decode(data['data']).decode('utf-8')
file_name = data['attributes']['file_name']
This following R code builds a R dataframe and converts it to json content:
library(jsonlite)
data="Hello World!"
df <- data.frame(data)
attributes <- data.frame(file_name=c('gfs_data_temp_FULL.csv'))
df$attributes <- attributes
msg <- df %>%
toJSON(auto_unbox = TRUE, dataframe = 'columns', pretty = T) %>%
# Pub/Sub expects a base64 encoded string
googlePubsubR::msg_encode() %>%
googlePubsubR::PubsubMessage()
It seems good but when I visualise it with a json editor :
indexes are added.
Additionally there is the message content:
I dont'sure it respects Google Cloud Pub Sub message format...
ANSWER
Answered 2022-Apr-16 at 09:59Not sure why, but replacing the dataframe by a list seems to work:
library(jsonlite)
df = list(data = "Hello World")
attributes <- list(file_name=c('toto.csv'))
df$attributes <- attributes
df %>%
toJSON(auto_unbox = TRUE, simplifyVector=TRUE, dataframe = 'columns', pretty = T)
Output:
{
"data": "Hello World",
"attributes": {
"file_name": "toto.csv"
}
}
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
No vulnerabilities reported
Find more information at:
Save this library and start creating your kit
Save this library and start creating your kit
Open Weaver – Develop Applications Faster with Open Source