How do i use nested data from a Data output? i want to covert data to message #5929
Replies: 1 comment 8 replies
-
Hello, @danielAsaboro! I'm here to help you with any bugs, questions, or becoming a contributor. Let's squash some bugs together! 🤖 To extract nested data from your JSON output and form a coherent template for a Data to Message component, you can use the
Here's an example of how you might implement this: from langflow.schema import Data
from langflow.custom import Component
from langflow.schema.message import Message
# Example JSON data
json_data = Data(data={
"bounties": [
{
"title": "Build an AI Solution to Supercharge Superteam Vietnam’s Communication",
"sponsor": "Superteam Vietnam",
"total_reward": "1,500USDC",
"prizes": [
{"amount": "1,000", "token": "USDC", "position": "1st"},
{"amount": "500", "token": "USDC", "position": "2nd"}
],
"deadline": "1d:21h:10m",
"description": "Objective: Superteam Vietnam relies on human effort...",
"resources": [{"url": "https://www.youtube.com/watch?v=3fKORXMJ6RE"}],
"skills_needed": [{"skill": "Backend"}],
"contact_info": "mailto:[email protected]",
"source_url": "https://earn.superteam.fun/listing/build-an-ai-solution-to-supercharge-superteam-vietnams-communication/"
}
]
})
# Template to extract bounty details
template = "Title: {bounties[].title}\nSponsor: {bounties[].sponsor}\nTotal Reward: {bounties[].total_reward}\nDeadline: {bounties[].deadline}\nContact: {bounties[].contact_info}"
# Initialize the component
class ParseDataComponent(Component):
def parse_data(self, data, template, sep="\n"):
# Implement the logic to parse data using the template
# This is a placeholder for the actual implementation
return Message(text="Formatted message based on template")
component = ParseDataComponent()
formatted_message = component.parse_data(json_data, template)
# Output the results
print(formatted_message.text) This example demonstrates how to extract and format specific details from the JSON data using a template. Adjust the To continue talking to Dosu, mention @dosu. Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other |
Beta Was this translation helpful? Give feedback.
-
my code outputs this:
but I can't seem to extract nested parts to form a coherent template for the Data to Message component;
please how do I go about it?
Beta Was this translation helpful? Give feedback.
All reactions