Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi there
I have designed my job like below which shows result as NULL. I am sure my tExtractjsonFields is not configured properly.
Trying to extract Json (as shown below) using URL:
[ { "assignment_id": 1234, "title": "Assignment 1", "points_possible": 10, "due_at": "2012-01-25T22:00:00-07:00", "unlock_at": "2012-01-20T22:00:00-07:00", "muted": false, "min_score": 2, "max_score": 10, "median": 7, "first_quartile": 4, "third_quartile": 8, "module_ids": [ 1, 2 ], "submission": { "submitted_at": "2012-01-22T22:00:00-07:00", "score": 10 } }, { "assignment_id": 1235, "title": "Assignment 2", "points_possible": 15, "due_at": "2012-01-26T22:00:00-07:00", "unlock_at": null, "muted": true, "min_score": 8, "max_score": 8, "median": 8, "first_quartile": 8, "third_quartile": 8, "module_ids": [ 1 ], "submission": { "submitted_at": "2012-01-22T22:00:00-07:00" } } ]
My tExtractJsonFields is configred as below:
Can someone please guide what am I doing wrong?
Thanks
Harshal.
It looks like you have different JSON schemas arriving into your job. You need to first identify which schema you are working with and then configure a tExtractJSONField to cater for each schema. I don't think you will find a one size fits all solution for this.
Use a tExtractJSONField component to test for an element you know will be in one of the schemas you need to deal with. If it returns a value, then you know that is the correct schema and you can them retrieve the rest of the values. If the value is null, then you know the schema is not correct and it must be one of the other schema types. Keep doing that until you find the correct schema and process the data from there.
It might mean using several tExtractJSONField components, but it will allow you to process multiple types in one job.
For example....
Input file ---->tExtractJSONField (for schema 1) ----> Rest of the job
---->tExtractJSONField (for schema 2) ----> Rest of the job
---->tExtractJSONField (for schema 3) ----> Rest of the job
This is what I used to solve problems like this....
I see. This is a difficult one. I don't believe (I may be wrong) that this is possible with Talend at the moment. What you could do is identify if the schema is of this type using a JSONPath like this....
$.*.studentMessages
.... and if it is, using a slightly different approach to get the data. The approach I have used before (I'm afraid I do not have the code at hand) is to build Java code to return all of the key/value pairs and then interrogating the Java object for your data. An example of this approach (albeit not perfect, hence the question it is associated to) can be seen here...
@rhall: Does it mean something like this?
Usual flow of loop/itetrate -> Java code to get keys/pair -> output to DB.
hi,
making json valid means checking syntactical validity of your json file
for ex. consider json below
{
"parentkey1": {
"childkey1": "childvalue1",
"childkey2": "childvalue2" ,
}
}
in above json the comma on line 4 is invalid ,it should not be there because there are no more childkeys after that .
the "childkey2":"childvalue2" is the last key value pair so there should not be any comma after that.
Before reading any of your json files you should check if they are valid or not.
You can do this online easily.
Regards
Chandra Kant