In a scenario where I receive an object of varying length that I do not control, I am required to extract specific data from it.
The response I receive is in the form of a formatted string:
{
"questionId": 18196101,
"externalQuestionId": "bcc38f7d30ea44ad908d8166dafa5556",
"category": "Employment Law",
"secondaryCategory": "",
"partnerName": "",
"questionTitle": "I sold my business but was offered a job with the company as",
"questionText": "I sold my business but was offered a job with the company as manager..."
}
The string representation is:
'{"questionId":18196101,"externalQuestionId":"bcc38f7d30ea44ad908d8166dafa5556","category":"Employment Law","secondaryCategory":"","partnerName":"","questionTitle":"I sold my business but was offered a job with the company as","questionText":"I sold my business but was offered a job with the company as manager..."}'
Given that I have access to both the questionTitle
and questionText
, I can search for their indexes within the string. This becomes necessary since this object may be embedded in a larger response at different positions.
The extraction task involves retrieving the externalQuestionId
, such as
"bcc38f7d30ea44ad908d8166dafa5556"
in this example.
Due to the dynamic nature of the numbers involved, identifying the indexes of known parameters is crucial.
Essentially, with knowledge of the starting index of questionTitle
, the challenge is to locate the nearest occurrence of externalQuestionId
.