How to seperate two json files by string? - json
I am trying to parse a JSON from a website in order to extract some data. Somehow the JSON is "combined", meaning that the dataset for one product is described and without separating the next, the JSON simply continues. This throws an error in json.load (python3.8).
Here is the part in question:
"name": "30 stk"
}
}
} {
"#type":"Product"
jsonlint outputs the following error:
Error: Parse error on line 126:
...30 stk" } } } { "#type": "Produc
--------------------^
Expecting 'EOF', '}', ',', ']', got '{'
Full JSON:
{"#context":"https://schema.org","#type":"Product","#id":"/antistax-extra-venentabletten-bei-venenleiden-60stk-pzn-00002335","aggregateRating":{"#type":"AggregateRating","ratingValue":"4,8","reviewCount":"26"},"description":"AntistaxextraVenentablettenbeiVenenleiden60stkkaufenbeiderOnlineApothekeapo-discounter.Medikamente,Nahrungsergänzungenuvm.erhaltenSieinunsererVersandapothekezugünstigenPreisen.","name":"AntistaxextraVenentablettenbeiVenenleiden(60stk)","image":"https://www.apodiscounter.de/images/product_images/info_images/00002335_4.jpg","sku":"00002335","mpn":"00002335","productID":"00002335","category":"Venenerkrankung","brand":{"#type":"Organization","name":"Antistax"},"offers":{"#type":"Offer","availability":"https://schema.org/InStock","url":"https://www.apodiscounter.de/antistax-extra-venentabletten-bei-venenleiden-60stk-pzn-00002335","price":"27.49","priceValidUntil":"2021-01-26","priceCurrency":"EUR","category":"Filmtabletten","eligibleQuantity":"60stk","itemCondition":"NewCondition","seller":{"#type":"Organization","name":"apo-discounter.de"}},"issimilarto":[{"#type":"Product","mpn":"00002312","name":"AntistaxextraVenentablettenbeiVenenleiden","url":"https://www.apodiscounter.de/antistax-extra-venentabletten-bei-venenleiden-30stk-pzn-00002312","description":"AntistaxextraVenentablettenbeiVenenleiden30stkkaufenbeiderOnlineApothekeapo-discounter.Medikamente,Nahrungsergänzungenuvm.erhaltenSieinunsererVersandapothekezugünstigenPreisen.","image":"https://www.apodiscounter.de/images/product_images/info_images/00002312.jpg","sku":"00002312","brand":{"#type":"Organization","name":"Antistax"},"aggregateRating":{"#type":"AggregateRating","ratingValue":"5,0","reviewCount":"13"},"review":[{"#type":"Review","author":"ErnaD.","datePublished":"30.10.2020","description":"","name":"","reviewRating":{"#type":"Rating","bestRating":"5","ratingValue":"5","worstRating":"1"}},{"#type":"Review","author":"DomenicaZ.","datePublished":"04.09.2020","description":"","name":"","reviewRating":{"#type":"Rating","bestRating":"5","ratingValue":"5","worstRating":"1"}},{"#type":"Review","author":"RitaS.","datePublished":"11.07.2020","description":"kaumwirksam","name":"","reviewRating":{"#type":"Rating","bestRating":"5","ratingValue":"5","worstRating":"1"}},{"#type":"Review","author":"VerifizierterKunde","datePublished":"10.04.2020","description":"Binnichtganzüberzeugt","name":"","reviewRating":{"#type":"Rating","bestRating":"5","ratingValue":"5","worstRating":"1"}},{"#type":"Review","author":"VerifizierterKunde","datePublished":"06.03.2020","description":"BinpositivüberraschtvondemProdukt","name":"","reviewRating":{"#type":"Rating","bestRating":"5","ratingValue":"5","worstRating":"1"}}],"offers":{"#type":"Offer","availability":"https://schema.org/InStock","url":"https://www.apodiscounter.de/antistax-extra-venentabletten-bei-venenleiden-30stk-pzn-00002312","price":"15.99","priceValidUntil":"2021-01-26","priceCurrency":"EUR","eligibleQuantity":{"#type":"QuantitativeValue","name":"30stk"}}}{"#type":"Product","mpn":"05954715","name":"AntistaxextraVenentablettenbeiVenenschwäche","url":"https://www.apodiscounter.de/antistax-extra-venentabletten-bei-venenschwaeche-90stk-pzn-05954715","description":"AntistaxextraVenentablettenbeiVenenschwäche90stkkaufenbeiderOnlineApothekeapo-discounter.Medikamente,Nahrungsergänzungenuvm.erhaltenSieinunsererVersandapothekezugünstigenPreisen.","image":"https://www.apodiscounter.de/images/product_images/info_images/05954715.jpg","sku":"05954715","brand":{"#type":"Organization","name":"Antistax"},"aggregateRating":{"#type":"AggregateRating","ratingValue":"4,8","reviewCount":"167"},"review":[{"#type":"Review","author":"VerifizierterKunde","datePublished":"05.12.2020","description":"","name":"","reviewRating":{"#type":"Rating","bestRating":"5","ratingValue":"5","worstRating":"1"}},{"#type":"Review","author":"RoswithaT.","datePublished":"23.11.2020","description":"","name":"","reviewRating":{"#type":"Rating","bestRating":"5","ratingValue":"5","worstRating":"1"}},{"#type":"Review","author":"RalfZ.","datePublished":"22.11.2020","description":"Gutundpreiswert!","name":"","reviewRating":{"#type":"Rating","bestRating":"5","ratingValue":"5","worstRating":"1"}},{"#type":"Review","author":"ReinhardS.","datePublished":"22.11.2020","description":"","name":"","reviewRating":{"#type":"Rating","bestRating":"5","ratingValue":"5","worstRating":"1"}},{"#type":"Review","author":"VerifizierterKunde","datePublished":"08.11.2020","description":"WennmanProblememitVenenhatundlangeaufdenBeinenist,hilftesdenTagbesserzumeistern...","name":"","reviewRating":{"#type":"Rating","bestRating":"5","ratingValue":"5","worstRating":"1"}}],"offers":{"#type":"Offer","availability":"https://schema.org/InStock","url":"https://www.apodiscounter.de/antistax-extra-venentabletten-bei-venenschwaeche-90stk-pzn-05954715","price":"33.49","priceValidUntil":"2021-01-26","priceCurrency":"EUR","eligibleQuantity":{"#type":"QuantitativeValue","name":"90stk"}}},{"#type":"Product","mpn":"16156023","name":"AntistaxextraVenentablettenbeiVenenleiden&Venenschwäche","url":"https://www.apodiscounter.de/antistax-extra-venentabletten-bei-venenleiden-venenschwaeche-180stk-pzn-16156023","description":"AntistaxextraVenentablettenbeiVenenleiden&Venenschwäche180stkkaufenbeiderOnlineApothekeapo-discounter.Medikamente,Nahrungsergänzungenuvm.erhaltenSieinunsererVersandapothekezugünstigenPreisen.","image":"https://www.apodiscounter.de/images/product_images/info_images/16156023.jpg","sku":"16156023","aggregateRating":{"#type":"AggregateRating","ratingValue":"5,0","reviewCount":"3"},"review":[{"#type":"Review","author":"IrinaL.","datePublished":"20.01.2021","description":"","name":"","reviewRating":{"#type":"Rating","bestRating":"5","ratingValue":"5","worstRating":"1"}},{"#type":"Review","author":"AlfredS.","datePublished":"20.01.2021","description":"","name":"","reviewRating":{"#type":"Rating","bestRating":"5","ratingValue":"5","worstRating":"1"}},{"#type":"Review","author":"VerifizierterKunde","datePublished":"11.01.2021","description":"","name":"","reviewRating":{"#type":"Rating","bestRating":"5","ratingValue":"5","worstRating":"1"}}],"offers":{"#type":"Offer","availability":"https://schema.org/InStock","url":"https://www.apodiscounter.de/antistax-extra-venentabletten-bei-venenleiden-venenschwaeche-180stk-pzn-16156023","price":"56.49","priceValidUntil":"2021-01-26","priceCurrency":"EUR","eligibleQuantity":{"#type":"QuantitativeValue","name":"180stk"}}}],"review":[{"#type":"Review","author":"KlausS.","datePublished":"11.12.2020","description":"","name":"","reviewRating":{"#type":"Rating","bestRating":"5","ratingValue":"4","worstRating":"1"}},{"#type":"Review","author":"OttiZ.","datePublished":"19.10.2020","description":"Zufrieden","name":"","reviewRating":{"#type":"Rating","bestRating":"5","ratingValue":"5","worstRating":"1"}},{"#type":"Review","author":"MonikaM.","datePublished":"03.09.2020","description":"","name":"","reviewRating":{"#type":"Rating","bestRating":"5","ratingValue":"5","worstRating":"1"}},{"#type":"Review","author":"RitaP.","datePublished":"14.08.2020","description":"","name":"","reviewRating":{"#type":"Rating","bestRating":"5","ratingValue":"5","worstRating":"1"}},{"#type":"Review","author":"VerifizierterKunde","datePublished":"24.07.2020","description":"","name":"","reviewRating":{"#type":"Rating","bestRating":"5","ratingValue":"3","worstRating":"1"}}]}
How can I separate those two or is there a function for this? I tried .split('} {') but this did not work.
It seems you have a JSON array containing two JSON objects not separated by a comma.
You should just replace } { with }, {.
Related
I am getting the error in below JSON format "Expecting 'STRING', got '{'"
I am getting error while validating the below JSON. Can you please explain why ? In JSON, can't we put one curly braces inside another ? { "header":{ "appId":"xxyy" ,"token":"token" ,"messageId":"messageId" } ,{ "message_timestamp":"2022-12-07 11:35::44" ,"wins2rms":{ "data_ind":"NONSELLABLE" ,"data_row":6 ,"data_set":[ { "loc":"9981" ,"loc_type":"W" ,"item":"00000160" ,"qty":20 ,"reason":"Q" ,"rms_ind":"Y" } ] } } } Error: Parse error on line 6: ...": "messageId" }, { "message_timesta ---------------------^ Expecting 'STRING', got '{' Thanks
The error is caused by the fact that the JSON object you have provided is not valid. In JSON, objects are represented using curly braces ({ and }). You cannot put one set of curly braces inside another, as you have done on lines 6 and 7. Here is how the JSON object should be formatted: { "header":{ "appId":"xxyy", "token":"token", "messageId":"messageId" }, "message_timestamp":"2022-12-07 11:35::44", "wins2rms":{ "data_ind":"NONSELLABLE", "data_row":6, "data_set":[ { "loc":"9981", "loc_type":"W", "item":"00000160", "qty":20, "reason":"Q", "rms_ind":"Y" } ] } } In this version of the JSON object, the nested objects are properly formatted, with each object enclosed in its own set of curly braces. You can use a JSON validation tool to verify that the object is valid.
The error is caused while validating is because of JSON syntax error. We can use nested JSON objects but, the it is used are not a valid syntax. In the following JSON object 6th and 7th line has an syntax error. You cannot but one set of curly braces inside another with an comma. ,"messageId":"messageId" } ,{ "message_timestamp":"2022-12-07 11:35::44" In above object can modified as. ,"messageId":"messageId" } "message_timestamp":"2022-12-07 11:35::44" We can use curly braces inside another with an comma in an array of JSON object. Below is an example that showcases how it can be used. { "array":[ { "name":"test1" }, { "name":"test2" }, { "name":"test3" }, ] }
How to pass a JSON string to API Gateway as query Parameter
How can i pass a JSON object like {val: 1} to my Lambda function as a query parameter? Following Standardized way to serialize JSON to query string? i URL-encoded my JSON object and requested the following: mysite.com/path?json=%7B%22val%22%3A%201%7D As requestTemplates i tried the following two options "json": "$input.params().querystring.json" "json": "$util.parseJson($input.params().querystring.json)" But i got this error message: {"message": "Could not parse request body into json: Unexpected character (\'v\' (code 118)): was expecting comma to separate OBJECT entries\n at [Source: [B#37a2970e; line: 1, column: 47]"} If i do not encode the query string so: mysite.com/path?json={"val":1} i get a 400 error
Your mapping template is producing no valid JSON, you have to wrap the key/value pair in curly braces I guess you do not want to wrap the value in quotes, it will be a string and no object otherwise You can use $util.urlDecode to decode URL encoded strings Your mapping template should look like this: {"json": $util.urlDecode($input.params().querystring.json)} For mysite.com/path?json=%7B%22val%22%3A%201%7D this mapping template will result in the following JSON: { "json": { "val": 1 } } If you want the querystring JSON to be passed on the root level to your Lambda function use this as a mapping template: $util.urlDecode($input.params().querystring.json)
Are line feeds allowed in JSON strings?
I need to send XML inside a JSON for my REST OSB 12c Proxy as follow: { "login": "jstein", "identityContext": "jazn.com", "taskId": "string", "payload": { "any_0": { "any_01": "<afastamento xmlns:ns1='http: //www.tjsc.jus.br/soa/schemas/comagis/AfastamentoMagistrado' xsi:type='def: AfastamentoMagistradoType' xmlns:xsi='http: //www.w3.org/2001/XMLSchema-instance' xmlns='http: //xmlns.oracle.com/bpel/workflow/task'> <ns1:Magistrado>719</ns1:Magistrado> <ns1:Status>Inicial</ns1:Status> <ns1:Vaga>8770</ns1:Vaga> <ns1:Tipo>Licenca Nojo</ns1:Tipo> <ns1:PeriodoReferencia/> <ns1:DataInicialSolicitada>2015-10-10</ns1:DataInicialSolicitada> <ns1:DataFinalSolicitada>2015-11-05</ns1:DataFinalSolicitada> </afastamento>" } }, "outcome": "Start" } The OSB 12c send me back the error: "errorMessage" : "ORABPEL-15235\n\nTranslation Failure.\nFailed to translate JSON to XML. org.codehaus.jackson.JsonParseException: Illegal unquoted character ((CTRL-CHAR, code 10)): has to be escaped using backslash to be included in string value\n at [Source: java.io.BufferedReader#7db921c7; line: 7, column: 619]\nThe incoming data does not conform to the NXSD schema. Please correct the problem.\n" I am testing my JSON request at JSONLint, and it always gives me the error about start a String with <: Parse error on line 7: "any_01": "<afastamento xmlns: -----------^ Expecting 'STRING, 'NUMBER, 'NULL', 'TRUE', FALSE', '{', '['
No, literal line feeds (CTRL-CHAR, code 10) and newlines are control characters that are not allowed within a JSON string: XML does not require the line feeds between elements. You can simply remove them, changing your multi-line XML document to an equivalent single-line XML document that will be able to be passed as a JSON string without problem. Or, you may want to consider escaping the line feeds \n, or more generally, escaping the entire string: How should I escape strings in JSON? [Java] In C# how to encode XML to output it inside JSON in the JavaScript part of a page
What's wrong with this JSON object?
What's wrong with this? { 'z': 'hello' } Looks like a valid JavaScript dictionary to me, but both Python JSON and http://pro.jsonlint.com/ are telling me Parse error on line 1: { 'z': 'hello'} -----^ Expecting 'STRING', '}' What am I doing wrong?
Strings must be delimited by double quotes in JSON: http://www.json.org/ They can be single quoted in Python and JavaScript, but JSON is a very small subset of JavaScript.
Groovy JsonSlurper JSON value with escaped quotation marks
I'm developing a small tool written in Groovy which parses JSON strings in emails. Some of these JSON strings have JSON values that contain escaped quotes. For example: { "hello": "world with \"quotation marks\"" } To parse these strings, I am using Groovy's JsonSlurper. The following code demonstrates my problem: import groovy.json.JsonException import groovy.json.JsonSlurper try { print new JsonSlurper().parseText(''' { "hello": "world with \"quotation marks\"" } ''') } catch (JsonException | IllegalArgumentException e) { print e } See https://groovyconsole.appspot.com/script/6193189027315712 for a live demo. When executing this code, the following exception is thrown: groovy.json.JsonException: expecting '}' or ',' but got current char 'q' with an int value of 113 The current character read is 'q' with an int value of 113 expecting '}' or ',' but got current char 'q' with an int value of 113 line number 3 index number 35 "hello": "world with "quotation marks"" ............................^ Thus, the escaping of the quotation mark is ignored by JsonSlurper. Unfortunately, I have no control over the input, i.e. the JSON strings. Therefore, I have to find a way to parse such a JSON string into a map or any other appropriate data structure.
The string has not been escaped properly in the json. The text data should be like: ''' { "hello": "world with \\\"quotation marks\\\"" } ''' The string that you are getting indicates that the mail body contains the json in format: { "hello": "world with "quotation marks"" } while it should be like { "hello": "world with \"quotation marks\"" } If earlier is the case then you can't parse the invalid json as there is no way for code to identify about the escaped data.