I've got a well formated JSON string with a R script, but when I try to parse it using the rjson package (with parser$addData), I get this error :
>json <- fromJSON(docret)
>parser <- newJSONParser()
>parser$addData(json)
Erreur dans strsplit(buf, "") :
l'argument n'est pas une chaîne de caractères
My JSON string (docret here) is validated by two online JSON validators.
Can I do something about this error to have my JSON object usable?
Here is my JSON :
http://shrib.com/8dTgq90U
Related
I try to write a JSON to a file to use in another program. I have a dataframe which I make into a JSON like this:
jsontest = df_qnapairs.to_json(orient = 'records', force_ascii = False)
The output is this
Out[9]: '[{"id":1,"answer":"Status på Anleggsoverenskomsten er Oppgjør vedtatt","source":"Automatic","questions":["Hva er status på Anleggsoverenskomsten","Hvordan går det med Anleggsoverenskomsten","Når skjer Anleggsoverenskomsten","Status på Anleggsoverenskomsten","Fortell meg når Anleggsoverenskomsten skjer"],"metadata":[]},{"id":2,"answer":"Status på Kraftlinjefirmaer er Ikke oppgitt","source":"Automatic","questions":["Hva er status på Kraftlinjefirmaer","Hvordan går det med Kraftlinjefirmaer","Når skjer Kraftlinjefirmaer","Status på Kraftlinjefirmaer","Fortell meg når Kraftlinjefirmaer skjer"],"metadata":[]}]'
The problem is that the input program runs an error because of the preceding "'[" and trailing "']". How can I remove these when writing to the file?
if u remove "[" and "]" from it, you change its type from json to dict and in the other program you must be work with dict, i recommend to read and write on file in json format.
if u want to load json in other program you can use :
import json
json_var = json.loads(var)
if u force to do it, u can change it to string and remove "[" and "]" :
var = str(jsontest)[1:len(str(jsontest))-1]
How can we import a csv file with specific caractere in colnames ? When I open this CSV with Visual Code, 2 colnames contain this caractere �. Is there a way to import my file with proc import (not a datastep) ?
SAS version 9.04
I try this :
filename test2 "my_file.csv" encoding="utf-8" ;
proc import datafile= test2
out=my_df
dbms=dlm
replace;
delimiter=";";
getnames=yes;
GUESSINGROWS=MAX;
run;
Raise an error :
ERROR: Invalid string.
ERROR: Invalid string.
ERROR: Invalid string.
Nombre de noms trouvé inférieur au nombre de variables trouvé.
Le nom n'est pas un nom SAS correct.
Problèmes détectés dans les noms fournis. Consultez le Journal.
....
ERROR: Invalid string.
FATAL: Unrecoverable I/O error detected in the execution of the DATA step program. Aborted during
the EXECUTION phase.
Do the trick encoding="Windows-1250":
filename test2 "my_file.csv" encoding="Windows-1250" ;
proc import datafile= test2
out=my_df
dbms=dlm
replace;
delimiter=";";
getnames=yes;
GUESSINGROWS=MAX;
run;
Tips : to choose right encoding :
File > Import data > Choose your file ... > In open window click on "Codage ..." > In my case Codage "Europe de l'Ouest (Windows) (Page de code 1252) Import correctly "é" : check below in overview.
To have right syntax of encoding "1250" refers to : https://support.sas.com/documentation/onlinedoc/dfdmstudio/2.6/dmpdmsug/Content/dfU_Encodings.html
The invalid format:
"studwhere": "Academia de Muzica "Gheorghe Dima" Cluj-Napoca",
Expected result:
"studwhere": "Academia de Muzica Gheorghe Dima Cluj-Napoca",
or
"studwhere": "Academia de Muzica \"Gheorghe Dima\" Cluj-Napoca",
Hi im reading a CSV file (to get information from a WEB Service) with this values:
169233xxx
169129xxx
189925xxx
This is my keyword definition:
Carga RUTs
[Documentation] Carga lista de RUTs a validar desde archivo csv
[Arguments] ${file_name}
${data}= read csv file ${file_name}
[return] ${data}
I catch this values in a for:
Consultar WS
[Documentation] Lee RUTs de archivo csv y consulta cada uno al Experto Original y Migrado.
[Arguments] ${data}
${rutsd}= Set Variable 0
Log To Console .
:FOR ${element} IN #{data}
\ ${rutsd}= Fetch From Left ${element}[0] ;
\ ${dvymas}= Get Substring ${element}[0] -2
\ Log To Console Consultando RUT ${rutsd}...
\ Run Keyword And Continue On Failure WS Experto Orignal ${rutsd}
At the moment of consulting....Appears for each "[" or "$apos" icon , i dont understand
<ns1:rut>['189925xxx </ns1:rut>
<ns1:rut>[$apos 189925xxx </ns1:rut>
At finally response:
Server raised fault: '1001: RUT no Válido' (translate DNI invalid(
Can someone explain to me why I am getting this error?
Thanks,
Regards!!
EDIT:
To not creat a new post i have a new error, i modified
${element}[0] for #{element}[0]
The previous error was solved.
Now i have a new error:
List variable '#{element}' has no item in index 0
Can someone explain to me why I am getting this error?
thanks again
Since the streamR connection API doesn't work anymore on Tweeter I try to convert the output from searchTwitter function (from TwitteR) into BSON before insert it in a mongodb database.
test.tweets = searchTwitter("mongodb", n=10, lang="en")
class(test.tweets)
test.text=laply(test.tweets,function(t) t$getText())
class(toJSON(test.text))
bson <- mongo.bson.from.JSON(test.text)
R return an error : "Error in mongo.bson.from.JSON(test.text) : Not a valid JSON content:..."
How to resolve this conversion or does exist another solution ?
Thank you
This works
library(rmongodb)
library(jsonlite)
test.text <- c("A tweet", "Another tweet")
(bson <- mongo.bson.from.JSON(toJSON(test.text)))
# 1 : 2 A tweet
# 2 : 2 Another tweet