0

I have a valid json file (checked it on online validator). I'm using tExtractJsonFields to extract the data. when I use JsonPath all is good but when I try to use xPath I get this error:

The content of elements must consist of well-formed character data or markup. Nested exception: The content of elements must consist of well-formed character data or markup.

I need to use xpath because I'm looping on a child element but I want to also get a root element which is the ID. using xpath I can do so with "../../id" but in jsonpath I can't go back to the root level. please I need help.

{
"expand": "names,schema",
"startAt": 0,
"maxResults": 1,
"total": 1580,
"issues": [
    {
        "expand": "operations,versionedRepresentations,editmeta,changelog,transitions,renderedFields",
        "id": "34202",
        "self": "https://...",
        "key": "DATA-1955",
        "changelog": {
            "startAt": 0,
            "maxResults": 4,
            "total": 4,
            "histories": [
                {
                    "id": "292501",
                    "author": {
                        "self": "https://tlassian.net/rest/api/2/user?accountId=.....",
                        "accountId": "651121611612",
                        "emailAddress": "test@sdfsdf.com",
                        "avatarUrls": {
                            "48x48": "https://secure.gravatar.com/avatar/a1440042a929a36696d609892772a08e?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FTH-2.png",
                            "24x24": "https://secure.gravatar.com/avatar/a1440042a929a36696d609892772a08e?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FTH-2.png",
                            "16x16": "https://secure.gravatar.com/avatar/a1440042a929a36696d609892772a08e?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FTH-2.png",
                            "32x32": "https://secure.gravatar.com/avatar/a1440042a929a36696d609892772a08e?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FTH-2.png"
                        },
                        "displayName": "test test",
                        "active": true,
                        "timeZone": "Asia/Beirut",
                        "accountType": "atlassian"
                    },
                    "created": "2020-11-12T14:42:42.397+0200",
                    "items": [
                        {
                            "field": "resolution",
                            "fieldtype": "jira",
                            "fieldId": "resolution",
                            "from": null,
                            "fromString": null,
                            "to": "10000",
                            "toString": "Done"
                        },
                        {
                            "field": "status",
                            "fieldtype": "jira",
                            "fieldId": "status",
                            "from": "3",
                            "fromString": "In Progress",
                            "to": "10001",
                            "toString": "Done"
                        }
                    ]
                },
                {
                    "id": "291885",
                    "author": {
                        "self": "https://......",
                        "accountId": "5f8ede6e9csdwd31840075146dc139b",
                        "emailAddress": "test@sdfsdf.com",
                        "avatarUrls": {
                            "48x48": "https://secure.gravatar.com/avatar/a1440042a929a36696d609892772a08e?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FTH-2.png",
                            "24x24": "https://secure.gravatar.com/avatar/a1440042a929a36696d609892772a08e?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FTH-2.png",
                            "16x16": "https://secure.gravatar.com/avatar/a1440042a929a36696d609892772a08e?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FTH-2.png",
                            "32x32": "https://secure.gravatar.com/avatar/a1440042a929a36696d609892772a08e?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FTH-2.png"
                        },
                        "displayName": "test test",
                        "active": true,
                        "timeZone": "Asia/test",
                        "accountType": "atlassian"
                    },
                    "created": "2020-11-12T13:40:13.232+0200",
                    "items": [
                        {
                            "field": "status",
                            "fieldtype": "jira",
                            "fieldId": "status",
                            "from": "10000",
                            "fromString": "To Do",
                            "to": "3",
                            "toString": "In Progress"
                        }
                    ]
                },
                {
                    "id": "291776",
                    "author": {
                        "self": "https://..........",
                        "accountId": "156516146865",
                        "emailAddress": "test@sdfsdf.com",
                        "avatarUrls": {
                            "48x48": "https://secure.gravatar.com/avatar/2e1767eb017dcb6bd02f8131f6b3613d?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FYM-6.png",
                            "24x24": "https://secure.gravatar.com/avatar/2e1767eb017dcb6bd02f8131f6b3613d?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FYM-6.png",
                            "16x16": "https://secure.gravatar.com/avatar/2e1767eb017dcb6bd02f8131f6b3613d?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FYM-6.png",
                            "32x32": "https://secure.gravatar.com/avatar/2e1767eb017dcb6bd02f8131f6b3613d?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FYM-6.png"
                        },
                        "displayName": "test test",
                        "active": true,
                        "timeZone": "Asia/test",
                        "accountType": "atlassian"
                    },
                    "created": "2020-11-12T13:36:39.861+0200",
                    "items": [
                        {
                            "field": "assignee",
                            "fieldtype": "jira",
                            "fieldId": "assignee",
                            "from": null,
                            "fromString": null,
                            "to": "5f8ede6e9c31840076dc139b",
                            "toString": "Test test",
                            "tmpFromAccountId": null,
                            "tmpToAccountId": "5f8ede6e9c31840076dc139b"
                        }
                    ]
                },
                {
                    "id": "289995",
                    "author": {
                        "self": "https://.........",
                        "accountId": "asdasd",
                        "emailAddress": "test@sdfsdf.com",
                        "avatarUrls": {
                            "48x48": "https://secure.gravatar.com/avatar/2e1767eb017dcb6bd02f8131f6b3613d?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FYM-6.png",
                            "24x24": "https://secure.gravatar.com/avatar/2e1767eb017dcb6bd02f8131f6b3613d?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FYM-6.png",
                            "16x16": "https://secure.gravatar.com/avatar/2e1767eb017dcb6bd02f8131f6b3613d?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FYM-6.png",
                            "32x32": "https://secure.gravatar.com/avatar/2e1767eb017dcb6bd02f8131f6b3613d?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FYM-6.png"
                        },
                        "displayName": "test test",
                        "active": true,
                        "timeZone": "Asia/sdsdsd",
                        "accountType": "atlassian"
                    },
                    "created": "2020-11-12T12:04:00.083+0200",
                    "items": [
                        {
                            "field": "Parent",
                            "fieldtype": "jira",
                            "from": null,
                            "fromString": null,
                            "to": "34194",
                            "toString": "DATA-1952"
                        }
                    ]
                }
            ]
        }
    }
]

}

this is my json file. you told me to upload my xpath that I used, but the thing is that the error is not in the xpath.

i have looped on "/issues" and extracted "key" as a field

jayzee
  • 195
  • 1
  • 17
  • Show the piece of your *data* and XPath that you tried – JaSON Nov 13 '20 at 09:41
  • So you're trying to navigate through JSON file and extract some data with XPath? – JaSON Nov 13 '20 at 09:57
  • yes but when i try xpath it does not work on this file in talend. i have tried another smaller file it did work using xpath. – jayzee Nov 13 '20 at 09:57
  • 1
    And this is correct behavior since JsonPath should be applied to JSON file and XPath to XML. XPath won't work with JSON! – JaSON Nov 13 '20 at 10:00
  • i have used XPATH it with another json file at it worked. If you can tell me how to get an element outside of the loop im into with jsonpath it should solve my problem. – jayzee Nov 13 '20 at 10:03

1 Answers1

0

I don't know which fields you want to extract, but it is doable with jsonpath, even if you have child elements and you want to get root elements.

Use talend json metadata to parse your json file (in Repository>Metadata>Json File).

Place your loop on your child element (lets say "$.issues[*].changelog.histories[*].items[*]" ) , you should then be able to pull all the fields you want in this child element, and also root elements.

Corentin
  • 2,442
  • 1
  • 17
  • 28