How to Extract JSON from AI response

I have a flow that scrapes 3 websites, has the openAI node summarise each site, then asks openAI to compare all 3 sites on set criteria. I ask for the output to be JSON format.

I get JSON output but all bundled up in JSON object(?) called “content”. I need to the out put in n8n usable JSON so I can map it for use with down flow nodes.

I am not a dev so working with code nodes is beyond me, but I can cut and paste and ask AI for help.

I have tried using an AI agent with a structured out put parser tool. But I don’t know how to set up the structured data in the tool so it fails. Not sure which is the right approach.

##The work flow is too big to share and hits character limit when sharing here

This is the output I get from Open AI from which I would like to extract the JSON, all under “content”

    "index": 0,
    "message": {
      "role": "assistant",
      "content": "{\n\"Company_names\": \n{\n\"Primary_company\": \n\"Taste of Cannabis\",\n\"Competitor_1\": \n\"Goodleaf\",\n\"Competitor_2\": \n\"Lowell Farms\",\n\"Competitor_3\": \n\"BIOMEDCAN\"\n},\n\"Company_Description\": \n{\n\"Primary_company\": \n\"Taste of Cannabis is a retailer specializing in a broad range of cannabis-based products with a clear focus on wellness and the therapeutic benefits of CBD (Cannabidiol) and other cannabinoids. Their product lineup includes CBD gummies, edibles such as cookies, CBD oil, and disposable vape cartridges containing various cannabinoid formulations.\",\n\"Competitor_1\": \n\"Goodleaf is a premium CBD brand in South Africa focused on health and wellness products. Their range includes all-natural CBD oil drops, CBD vapes, topical CBD creams, CBD water, sexual wellness products, and more. They emphasize quality by lab testing their products to ensure top-notch quality and promote wellness by sharing in-depth cannabis knowledge.\",\n\"Competitor_2\": \n\"Lowell Farms presents itself as a family of farms specializing in artisan craft cannabis. They emphasize their commitment to quality and sustainability, growing their products with natural materials from seed to sale. They offer a range of cannabis products, including oil, flower, and pre-rolls, with their operations based in California and extended to Massachusetts and Illinois.\",\n\"Competitor_3\": \n\"BIOMEDCAN is an online health store located in South Africa, specializing in the manufacture and retail of CBD products. They offer a range of CBD-based items including capsules, gels, tinctures, and even chocolate, all designed to provide natural remedies for various ailments.\"\n},\n\"Problem_It_Solves\": \n{\n\"Primary_company\": \n\"The company addresses the need for easily accessible, high-quality cannabis products that cater to individuals looking for natural alternatives to traditional medicine for relaxation, pain relief, anxiety management, and sleep improvement.\",\n\"Competitor_1\": \n\"Goodleaf addresses the problem of finding safe, reliable, and high-quality cannabis-derived products. They offer a solution for those seeking alternative remedies for stress, insomnia, pain, inflammation, and overall health maintenance. By providing lab-tested and carefully curated CBD products, Goodleaf ensures customers have access to trustworthy options in a market that can be inconsistent.\",\n\"Competitor_2\": \n\"The company solves the need for high-quality, ethically sourced, and crafted cannabis products. They address consumers' desire for a product that is both premium and produced with respect for the environment and the plant itself. By offering delivery and retail solutions across multiple states, Lowell Farms also solves the problem of accessibility to such products.\",\n\"Competitor_3\": \n\"BIOMEDCAN addresses the need for alternative treatments for conditions such as neurodegenerative disorders, chronic pain, anxiety, insomnia, depression, seizures, and acne. Their products are developed to offer benefits without the psychoactive effects typically associated with cannabis, as they contain zero THC.\"\n},\n\"Target_Audience\": \n{\n\"Primary_company\": \n\"Taste of Cannabis targets health-conscious consumers, particularly those interested in the potential wellness benefits of cannabis without the psychoactive effects typically associated with THC. This includes people with chronic pain, anxiety disorders, sleep difficulties, and anyone seeking a natural way to unwind and relax.\",\n\"Competitor_1\": \n\"The target audience for Goodleaf includes health-conscious consumers and individuals looking for alternative wellness solutions. This encompasses people dealing with stress, pain, sleep issues, skin problems, or simply those interested in the potential benefits of CBD products. Their audience may also include individuals who are conscious about ethical products, as suggested by certifications like organic, vegan, and cruelty-free endorsements.\",\n\"Competitor_2\": \n\"The target audience includes cannabis consumers who value sustainability, artisanal quality, and convenience. This likely includes a more discerning, possibly more mature or socially/environmentally conscious clientele. Given the nature of the product, the audience is restricted to adults over the age of 21.\",\n\"Competitor_3\": \n\"Their customer base includes individuals seeking natural and non-addictive treatment options for the aforementioned health issues. This likely encompasses adults of varying ages who are interested in wellness, alternative medicine, and specifically the benefits of CBD.\"\n},\n\"Unique_Business_Offer\": \n{\n\"Primary_company\": \n\"A variety of consumption methods, including edibles, oils, and vaping products, catering to customer preferences. A focus on product quality, offering vegan, gluten-free options, and broad/full-spectrum CBD products. Different potencies and formulations to suit various needs and preferences. Complimentary flavors and types of edibles, such as cookies and gummies, appealing to a broader audience. Products that enhance mood or focus (e.g., Energy Boost oil) indicate innovation in product development tailored to specific user experiences.\",\n\"Competitor_1\": \n\"Goodleaf unique offerings include a wide range of specially formulated CBD products that are organic, vegan society approved, and dermatologist approved. They also position themselves as an educational resource, with a blog called 'The Dose' and customer service dubbed 'Ask The Herbalist,' to guide customers on CBD usage. Their clear traceability and commitment to product transparency set them apart from others in the market.\",\n\"Competitor_2\": \n\"Lowell Farms differentiates itself by its commitment to natural and sustainable farming practices. Their 'Lowell Pledge' likely ensures customers are getting products free from harmful chemicals and in tune with artisanal cultivation methods. Furthermore, the delivery service 'Lowell Direct' in California, and the expansion to other states, extends the unique offer of convenience and broadens their market reach.\",\n\"Competitor_3\": \n\"BIOMEDCAN offers a unique proposition with their range of health-specific CBD products such as Mood, Sleep, Pleasure, and Skin capsules, as well as a Zero THC promise. They emphasize the combination of CBD with other active ingredients to maximize the desired effects. Additionally, their products are gluten-free and suitable for vegans.\"\n},\n\"Customer_Benefits\": \n{\n\"Primary_company\": \n\"Customers can expect to experience relaxation, reduced anxiety, improved sleep, and pain relief from using Taste of Cannabis products. The use of full-spectrum cannabinoids and terpene-enhanced distillate aims to maximize the entourage effect, potentially increasing the therapeutic benefit of the products.\",\n\"Competitor_1\": \n\"Customers can benefit from Goodleaf’s products through the potential alleviation of various ailments such as stress, pain, and insomnia. Additional benefits include the convenience of shopping for quality CBD products online with free shipping over a certain amount, comprehensive product information, and support from an educated concierge desk. Their ethical certifications ensure customers are purchasing products that align with conscientious values.\",\n\"Competitor_2\": \n\"Customers benefit from Lowell Farms' cultivation process which yields a purer, solventless cannabis experience. The increased quantity in what they call a 'Lowell Eighth', which actually consists of 4 grams of flower rather than the traditional 3.5, provides more value. Customers also enjoy the convenience of delivery and the assurance that the products they consume are responsibly farmed and ethically produced.\",\n\"Competitor_3\": \n\"Customers can expect a reduction in symptoms and improved health outcomes related to the use of BIOMEDCAN's products. The emphasized benefits include better sleep, enhanced mood, improved sexual experience, effective pain relief, and accelerated skin repair. The convenience of online shopping with delivery and the assurance of product quality through extensive testing are also significant benefits for consumers.\"\n},\n\"USP\": \n{\n\"Primary_company\": \n\"Taste of Cannabis emphasizes natural and potent ingredients, with a note on the synergistic effects of terpenes and cannabinoids. It positions itself in both the health and wellness market as well as the lifestyle space, suggesting a balance between medical benefits and enjoying the sensory experiences.\",\n\"Competitor_1\": \n\"Goodleaf's USP lies in their product quality with organic, vegan, and cruelty-free certifications and their commitment to educating customers about CBD and cannabis-related wellness. They stand out as a trusted source in South Africa for safe and tested CBD products, coupled with a strong commitment to customer support and satisfaction, providing a holistic and nurturing experience for users.\",\n\"Competitor_2\": \n\"Lowell Farms' USP lies in their sustainable and natural approach from seed to sale, coupled with their artisanal cultivation techniques. The cold-pressed cannabis oil, advertized as 'Pure. Natural. Solventless,' underscores their commitment to providing a pure experience close to the essence of the plant. Additionally, their commitment to providing more product per purchase with their 4-gram eighths, their variety of curated blends for different effects, and the availability of convenient delivery services and retail locations in select states solidify their unique market position.\",\n\"Competitor_3\": \n\"BIOMEDCAN's USP lies in their specialized formulations that pair CBD with other active ingredients to target specific health concerns. Their assurance of products being free from psychoactive effects (Zero THC), as well as free from heavy metals, microbiological contamination, or pesticides, positions them as a trustworthy brand in the growing CBD market. Additionally, the company's compliance with gluten-free and vegan standards further distincts them in an increasingly health-conscious consumer landscape.\"\n}\n}"
    "logprobs": null,
    "finish_reason": "stop"

Information on your n8n setup

  • n8n version: latest ai beta
  • Database (default: SQLite): sqlite
  • n8n EXECUTIONS_PROCESS setting (default: own, main): default
  • **Running n8n via (Docker, npm, n8n cloud, desktop app):**docker self hosted
  • **Operating system:**linux

hello @Robm

The provided output is not a valid JSON. Please, place the output under the code section (use the preformatted text button in the editor) to avoid any character encoding.

Thanks, thought I had done that, edited the original post


Now you can add the Edit Fields node after the AI output node to extract the JSON from the content

1 Like

That did it! I was sure the answer lied with the edit node, was just not sure how configutre it.

Thank you!

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.