Klassieke bestandstypen zijn vanaf januari 2021 niet meer beschikbaar voor gebruik. U kunt uw klassieke bestanden omzetten of een PDF downloaden. Meer informatie

Delimiter Issue

Beantwoord
0

Opmerkingen

2 opmerkingen

  • Wade Hays

    This happens when the API response returns a single line JSON string. If you know the structure of the JSON string you can get around it by using Handlebars to rebuild the JSON.

    If you have a JSON array like this:

    [{"id":1,"name":"Apple","price":1.25,"category":"Fruit","details":{"color":"Red","origin":"USA","organic":true},"reviews":[{"user":"Alice","rating":5,"comment":"Delicious!"},{"user":"Bob","rating":4,"comment":"Good, but a bit tart."}]},{"id":2,"name":"Banana","price":0.75,"category":"Fruit","details":{"color":"Yellow","origin":"Ecuador","organic":false},"reviews":[{"user":"Charlie","rating":3,"comment":"Okay, a little mushy."},{"user":"David","rating":5,"comment":"Perfect for smoothies!"}]},{"id":3,"name":"Carrot","price":0.50,"category":"Vegetable","details":{"color":"Orange","origin":"California","organic":true},"reviews":[{"user":"Eve","rating":4,"comment":"Fresh and crunchy."},{"user":"Frank","rating":5,"comment":"Great for snacks!"}]}]

    You could use a template like this:

    [
        {{#each data}}
        {
            "id": {{this.id}},
            "name": "{{this.name}}",
            "price": {{this.price}},
            "category": "{{this.category}}",
            "details":
            {
                "color": "{{this.details.color}}",
                "origin": "{{this.details.origin}}",
                "organic": {{this.details.organic}}
            },
            "reviews":
            [
                {{#each this.reviews}}
                {
                    "user": "{{this.user}}",
                    "rating": {{this.rating}},
                    "comment": "{{this.comment}}"
                }{{#unless @last}},{{/unless}}
                {{/each}}
            ]
        }{{#unless @last}},{{/unless}}
        {{/each}}
    ]

    and end up with JSON like this:


        { 
            "id": 1, 
            "name": "Apple", 
            "price": 1.25, 
            "category": "Fruit", 
            "details": 
            { 
                "color": "Red", 
                "origin": "", 
                "organic": true 
            }, 
            "reviews": 
            [ 
                { 
                    "user": "Alice", 
                    "rating": 5, 
                    "comment": "Delicious!" 
                }, 
                { 
                    "user": "Bob", 
                    "rating": 4, 
                    "comment": "Good, but a bit tart." 
                } 
            ] 
        }, 
        { 
            "id": 2, 
            "name": "Banana", 
            "price": 0.75, 
            "category": "Fruit", 
            "details": 
            { 
                "color": "Yellow", 
                "origin": "Ecuador", 
                "organic": false 
            }, 
            "reviews": 
            [ 
                { 
                    "user": "Charlie", 
                    "rating": 3, 
                    "comment": "Okay, a little mushy." 
                }, 
                { 
                    "user": "David", 
                    "rating": 5, 
                    "comment": "Perfect for smoothies!" 
                } 
            ] 
        }, 
        { 
            "id": 3, 
            "name": "Carrot", 
            "price": 0.5, 
            "category": "Vegetable", 
            "details": 
            { 
                "color": "Orange", 
                "origin": "", 
                "organic": true 
            }, 
            "reviews": 
            [ 
                { 
                    "user": "Eve", 
                    "rating": 4, 
                    "comment": "Fresh and crunchy." 
                }, 
                { 
                    "user": "Frank", 
                    "rating": 5, 
                    "comment": "Great for snacks!" 
                } 
            ] 
        }
    ]

     

    The output of the Handlebars - Render File Template can then be passed to the File Utils - Find and Replace to remove the pipe symbols.

     

    0
  • Chad Weber

    Thanks Wade

    This has worked 

    0

U moet u aanmelden om een opmerking te plaatsen.