JSON Missing ‘}’ or object member name - json

I was trying to help a friend use JSON commands in Windows 10 Minecraft which uses the JSON format. Well I entered this code below and I got the message
“ * Line 1, Column 2 Missing ‘}’ or object member name “
/give #p stick 1 0 {ench:[{"id":3,"lvl":3}]}

In order to be valid JSON, that object would need double-quotes around the ench key:
{"ench":[{"id":3,"lvl":3}]}
In the future, you can use a tool like jslint to validate JSON.

Related

Reading the Json string which is put together in one field

I have a Json pattern string in a text file, I have to pharse the below string like below and put it in to a external file.
Please let me know how this can be handled with Informatica Powercenter or Unix or Python?
{"CONTACTID":"3b2a25b2","ANI":"+16146748702","DNIS":"+18006081123","START_TIME":"01/22/2023 03:31:42","MODULE":[{"Name":"MainIVR","Time":"01/22/2023 03:31:42",Dialog":[{"name":"offer_Spanish","dialogeresult":"(|raw:7|R|7|1.0|nm=0|ni=0|2023/22/21 03:02:01)"}],"backend":[{"Time":"01/22/2023)"}],"END_STATE":"XC"}
In The above sample string the special charcters should be removed and the values should be assigned to the corresponding columns like below 2 o/p formats
Output:
CONTACTID, ANI, DNIS, START_TIME, MODULE, Time,Dialog,dialogeresult,END_STATE
3b2a25b2,+16146748702 +18006081123 01/22/2023 03:31:42,Name:MainIVR,
or
Output:
CONTACTID : 3b2a25b2
ANI:16146748702
DNI :+18006081123
I tried this to read thru Informatica powercenter and using the expression tranformations but nothing worked and tried with Python too.
For a start, your JSON is invalid. The opening double quotes for Dialog are missing and it's not properly closed - MODULE array is not closed and root is not closed. Here's the fixed JSON:
{"CONTACTID":"3b2a25b2","ANI":"+16146748702","DNIS":"+18006081123","START_TIME":"01/22/2023 03:31:42","MODULE":[{"Name":"MainIVR","Time":"01/22/2023 03:31:42","Dialog":[{"name":"offer_Spanish","dialogeresult":"(|raw:7|R|7|1.0|nm=0|ni=0|2023/22/21 03:02:01)"}],"backend":[{"Time":"01/22/2023)"}],"END_STATE":"XC"}]}
Use some JSON validation tool, like this one - it helps a lot.
Next, here's some starter code you may use to achieve the required result:
import json
# some JSON:
x = '{"CONTACTID":"3b2a25b2","ANI":"+16146748702","DNIS":"+18006081123","START_TIME":"01/22/2023 03:31:42","MODULE":[{"Name":"MainIVR","Time":"01/22/2023 03:31:42","Dialog":[{"name":"offer_Spanish","dialogeresult":"(|raw:7|R|7|1.0|nm=0|ni=0|2023/22/21 03:02:01)"}],"backend":[{"Time":"01/22/2023)"}],"END_STATE":"XC"}]}'
# parse x:
y = json.loads(x)
# the result is a Python dictionary:
print(y.keys())
You may test it on Replit
Finally regarding Informatica Powercenter - it is a terrible choice for complex string processing. You would need a Hierarchy Parser Transformation. Long story short: it's very tedious, but possible. I would highly recommend picking up a differen approach, if this is not a regular data loading process you will need to build.

Processing JSON from a .txt file and converting to a DataFrame in Julia

Cross posting from Julia Discourse in case anyone here has any leads.
I’m just looking for some insight into why the below code is returning a dataframe containing just the first line of my json file. If you’d like to try working with the file I’m working with, you can download the aminer_papers_0.zip from the Microsoft Open Academic Graph site, I’m using the first file in that group of files.
using JSON3, DataFrames, CSV
file_name = "path/aminer_papers_0.txt"
json_string = read(file_name, String)
js = JSON3.read(json_string)
df = DataFrame([js])
The resulting DataFrame has just one line, but the column titles are correct, as is the first line. To me the mystery is why the rest isn’t getting processed. I think I can rule out that read() is only reading the first JSON object, because I can index into the resulting object and see many JSON objects:
enter image description here
My first guess was maybe the newline \n was causing escape issues, and tried to use chomp to get rid of them, but couldn’t get it to work.
Anyway - any help would be greatly appreciated!
I think the problem is that the file is in JSON Lines format, and the JSON3 library only returns the first valid JSON value that it finds at the start of a string unless told otherwise.
tl;dr
Call JSON3.read with the keyword argument jsonlines=true.
Why?
By default, JSON3 interprets a string passed to its read function as a single "JSON text", defined by RFC 8259 section 1.3.2:
A JSON text is a serialized value....
(My emphasis on the use of the indefinite singular article "a.") A "JSON value" is defined in section 1.3.3:
A JSON value MUST be an object, array, number, or string, or one of the following three literal names: false, null, true.
A string with multiple JSON values in it is technically multiple "JSON texts." It is up to the parser to determine what part of the string argument you give it is a JSON text, and the authors of JSON3 chose as the default behavior to parse from the start of the string to the end of the first valid JSON value.
In order to get JSON3 to read the string as multiple JSON values, you have to give it the keyword option jsonlines=true, which is documented as:
jsonlines: A Bool indicating that the json_str contains newline delimited JSON strings, which will be read into a JSON3.Array of the JSON values. See jsonlines for reference. [default false]
Example
Take for example this simple string:
two_values = "3.14\n2.72"
Each one of these lines is a valid JSON serialization of a number. However, when passed to JSON3.read, only the first is parsed:
using JSON3
#assert JSON3.read(two_values) == 3.14
Using jsonlines=true, both values are parsed and returned as a JSON3.Array struct:
#assert JSON3.read(two_values, jsonlines=true) == [3.14, 2.72]
Other Packages
The JSON.jl library, which people might use by default given the name, does not implement parsing of JSON Lines strings at all, leaving it up to the caller to properly split the string as needed:
using JSON
JSON.parse(two_values)
# ERROR: Expected end of input
# Line: 1
# Around: ...3.14 2.72...
# ^
A simple way to implement reading multiple values is to use eachline:
#assert [JSON.parse(line) for line in eachline(IOBuffer(two_values))] == [3.14, 2.72]

How to know what is wrong in a JSON object?

I am trying to send the following JSON object and I get the error shown below,I checked #http://jsonviewer.stack.hu ,the JSON format seems to be correct,what am I missing and how to fix this?
{"component":{"name":"Company tech (New Bugs)", "version":"B"},"assignee":1234456,"milestone":"chiHW","priority":2,"state":"Analyze","substate":"Nominate","title":"[please ignore]CS\:4355C1\,4364B2\:WDI\:DHD\:HLK\(16299\)\-\>\"DF\ \-\ Sleep\ Tests\"\-\>Assert\-\>bcmpciedhd63\.sys\(dhd\_os\_ioctl\_resp\_wait\)\-\>dhd\_ndis\.c\#4449"}
Error:-
{"message":"An invalid JSON Object was passed in the request body. Please pass a valid JSON object.","help":"View documentation at http://bugs.company.com/","title":"Invalid Request","status":"400 Bad Request"}
You could have pasted your expression into https://jsonlint.com. It tells you where the problem is, and you can experiment until the JSON is no longer invalid. In your case, the problem is those backslashes in the last dictionary value (the one that starts "please ignore").
You could use jq to get a more specific parse error
watson:~$ cat >j
{"component":{"name":"Company tech (New Bugs)", "version":"B"},"assignee":1234456,"milestone":"chiHW","priority":2,"state":"Analyze","substate":"Nominate","title":"[please ignore]CS\:4355C1\,4364B2\:WDI\:DHD\:HLK\(16299\)\-\>\"DF\ \-\ Sleep\ Tests\"\-\>Assert\-\>bcmpciedhd63\.sys\(dhd\_os\_ioctl\_resp\_wait\)\-\>dhd\_ndis\.c\#4449"}
^D
watson:~$ jq <j
parse error: Invalid escape at line 1, column 333

Getting error while converting json file to a data frame using jsonlite

I am using the tweetscores package of R to get 'tweets list from twitter. The tweets are stored in json format. While converting it to a data frame I get a lexical error
' Error: lexical error: inside a string, '\' occurs before a character which it may not.".
Any solution to the mentioned error.
A part of the json file text
":[{"text":["MUFC"],"indices":[[83],[88]]}],"symbols":[],"user_mentions":[],"urls":[]},"metadata":{"iso_language_code":["en"],"result_type":["recent"]},"source":["http://twitter.com/download/iphone\" rel=\"nofollow\">Twitter for iPhone</a>"],"in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"user":{"id":[7.32108114527322e+017],"id_str":["732108114527322112"],"name":["wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww(^o^)/"],"screen_name":["SukiSukinal"],"location":["+6222"],"description":["Alliansi osaosi ngevote kagak. katanya sih fans a.k.a + "],"url":null,"entities":{"description":{"urls":[]}},"protected":[false],"followers_count":[163],"friends_count":[107],"listed_count":[4],"created_at":["Mon May 16 07:19:11 +0000
Json format does not allow backslashes so you need to escape them. replace any '\' character found with '\\'. Refer [here][1]
[1]: http://www.json.org/ for more info
You likely have an incomplete json string, which may be caused by the package or by an interrupted connection to Twitter's API. A complete json string returned from Twitter should look something like the following:
which I got using rtweet's stream_tweets() function. With a complete string returned by Twitter's REST or stream API, you should be able to convert the data using basically any json parser (e.g., jsonlite::fromJSON()).

Import JSON using WITH in Neo4j

I'm trying to use a JSON, to eventually import it into Neo4j.
I use something like, it's a big JSON string:
WITH [
{"fullname":"Full name","note":"f","addr":[],"phone":[],"email":[{"value":"mail#city.com"}],"first_name":"","last_name":""},
..
] AS contacts
The colors of the first contact is mostly orange, then the other contacts become green, then black.
I get the following error:
Invalid input '"': expected whitespace, an identifier, UnsignedDecimalInteger, a property key name or '}'
I can view my JSON file with http://jsonviewer.stack.hu/ And it looks fine
Do I need to escape some kind of character, so that Neo4j understands it?
Edit:
Based on Martins answer, I removed the quotes using a regex in PHP from:
Remove double-quotes from a json_encoded string on the keys
Remove the quotation marks around the keys. The error message tells you that it expects a property key. Cypher does not use JSON here.
WITH [
{fullname:"Full name",note:"f",addr:[],phone:[],
email:[{value:"mail#city.com"}],
first_name:"",last_name:""}
] AS contacts
RETURN contacts
A neo4j driver or client library will handle data passed from dictionary like structures as parameters: https://neo4j.com/docs/developer-manual/current/cypher/#cypher-parameters
If you want to work with JSON and maybe load it from external sources you should have a look at the APOC procedures: https://neo4j-contrib.github.io/neo4j-apoc-procedures/.
This for example converts a JOSN string to a map that can be used in Cypher: https://neo4j-contrib.github.io/neo4j-apoc-procedures/#_from_tojson
CALL apoc.convert.fromJsonMap(
'{"fullname":"Full name","note":"f","addr":[],"phone":[],
"email":[{"value":"mail#city.com"}],"first_name":"","last_name":""}'
)
YIELD value
RETURN value