How to create JSON string in Sequel Pro TEXT editor? - mysql

I figure this may be an unconventional way of creating a JSON string. But, I really need to just be able to make it right in "Sequel Pro" like this
I want to be able to just edit it right there like that. But when I receive the string on the client end, then try to use as3 JSON.parse function on it, it gets an error..."SyntaxError: Error #1132: Invalid JSON parse input."
private function storyTextCallBack(r:Object):void
{
//storyText is an 'Object'
storyText = JSON.parse(r.text);
}
But this is how my client is actually getting it, and it's what I think is breaking the JSON.parse function.....
[\n\t{\n\t\ttext: "hello this is some json test stuff",\n\t\tduration: "5000"\n\t},\n\t{\n\t\ttext: "this is the second line in that json object thing",\n\t\tduration: "3000"\n\t},\n\t{\n\t\ttext: "this is the third and final line in that json object thing",\n\t\tduration: "8000"\n\t}\n]
anyone have any ideas how I can fix this?

The object names in your JSON need to be inside quotes:
"text":"example text"
You can check if you have a valid JSON object with this parser: http://json.parser.online.fr

Related

Newtonsoft.Json.JsonSerializationException - Cannot deserialize the current JSON object

Lot of similar questions but still not able to make it. Here is my
code in vb.net and this is the json response. enter image description here I know this is because of [] but i'm using list don't know still getting the same error.
This is because you are receiving a JSON array and not a single JSON object.
You need to deserialize the array like this -
Dim Items_Array = Newtonsoft.Json.JsonConvert.DeserializeObject(Of T())(jsonString)

Invalid JSON syntax error in configuration file on homebridge

{
"bridge":{
"name":"Homebridge F8F5",
"username":"0E:8F:12:8D:F8:F5",
"port":51739,
"pin":"670-48-238"
},
"accessories":[
],
"platforms":[
{
"name":"Config",
"port":8581,
"platform":"config"
}
]
}{
"accessories":[
{
"name":"Roku",
"accessory":"Roku",
"ip":"http://10.204.1.238:8060",
}
I am getting an error when I try to run this config file in homebridge. What am I doing wrong? When I try to submit it through the web interface it will not allow me to and says “Config JSON error: invalid json syntax” Any help will be welcome! I have tried to put it through an online json error finder and it narrowed it down to this snippet.
Ummm... looks like you tried to edit this file without knowing the basic concepts of JSON.
Start by reading JSON - Introduction on W2Schools.com
Also, if you're not sure, use an online JSON validator. Use your fav. search engine to look for "JSON cleaner". (I use JSON Formatter & Validator at Curious Concept.)
Off the bat I can see a few issues with the JSON you provided.
the "}{" string ... what's that for? JSON cannot parse that ... either add "," between (if you wanted a new set) or (in this case) remove it.
you have two "accessories". JSON usually get parsed into an object or array ... one cannot have duplicates on the ket names. (In this case) remove the first one.
the second "accessories" array (denoted by "[") has no end (no "]")
the whole set (started with "{") has no end (no "}")

JSON won't parse Java list object

I am working with JSON and i have data to send in JSON form.I have field "stavka" which should be list of JSON objects,[{},{}...],and i have niz=["{"redni_broj":"3","naziv_robe_usluge":"gwe","kolicina:2","umanjeno_za_rabat":"43","ukupan_porez2":"33"}", "{"redni_broj":"9","naziv_robe_usluge":"12a","kolicina:55","umanjeno_za_rabat":"12","ukupan_porez2":"2"}"],and so I did "stavka":niz within JSON.stringify function,because niz looked as list of JSON objects..But when I send it,it says
"Can not construct instance of..no String-argument constructor/factory
method to deserialize from String value
('{"redni_broj":"3","naziv_robe_usluge":"gwe","kolicina":"123","jedinica_mere":"12","jedinicna_cena":"54","vrednost":"12","procenat_rabata":"1","iznos_rabata":"2","umanjeno_za_rabat":"43","ukupan_porez2":"33"}')
Does someone know why this happens?Shouldn't this be working?I thought it is the same as explicitly doing "stavka":[{"redni_broj":"3","naziv_robe_usluge":"gwe","kolicina:2","umanjeno_za_rabat":"43","ukupan_porez2":"33"}",{"redni_broj":"9","naziv_robe_usluge":"12a","kolicina:55","umanjeno_za_rabat":"12","ukupan_porez2":"2"}]
Thanks in advance!
there are some syntax error in your code. First, you can't write the array like this
niz = ["{"redni_broj":"3","naziv_robe_usluge":"gwe","kolicina:2","umanjeno_za_rabat":"43","ukupan_porez2":"33"}", "{"redni_broj":"9","naziv_robe_usluge":"12a","kolicina:55","umanjeno_za_rabat":"12","ukupan_porez2":"2"}"],
maybe you means niz is an array like niz = ['xx', 'xx'], but you just the " not ', "{"redni_broj":"3","naziv_robe_usluge":"gwe","kolicina:2","umanjeno_za_rabat":"43","ukupan_porez2":"33"}" is not a string, it is wrong way to use like that.
'{"redni_broj":"3","naziv_robe_usluge":"gwe","kolicina:2","umanjeno_za_rabat":"43","ukupan_porez2":"33"}' is right way.
Or you can try to use it like this way
"{\"redni_broj\":\"3\",\"naziv_robe_usluge\":\"gwe\",\"kolicina:2\",\"umanjeno_za_rabat\":\"43\",\"ukupan_porez2\":\"33\"}"

Parsing large JSON file with Scala and JSON4S

I'm working with Scala in IntelliJ IDEA 15 and trying to parse a large twitter record json file and count the total number of hashtags. I am very new to Scala and the idea of functional programming. Each line in the json file is a json object (representing a tweet). Each line in the file starts like so:
{"in_reply_to_status_id":null,"text":"To my followers sorry..
{"in_reply_to_status_id":null,"text":"#victory","in_reply_to_screen_name"..
{"in_reply_to_status_id":null,"text":"I'm so full I can't move"..
I am most interested in a property called "entities" which contains a property called "hastags" with a list of hashtags. Here is an example:
"entities":{"hashtags":[{"text":"thewayiseeit","indices":[0,13]}],"user_mentions":[],"urls":[]},
I've browsed the various scala frameworks for parsing json and have decided to use json4s. I have the following code in my Scala script.
import org.json4s.native.JsonMethods._
var json: String = ""
for (line <- io.Source.fromFile("twitter38.json").getLines) json += line
val data = parse(json)
My logic here is that I am trying to read each line from twitter38.json into a string and then parse the entire string with parse(). The parse function is throwing an error claiming:
"Type mismatch, expected: Nothing, found:String."
I have seen examples that use parse() on strings that hold json objects such as
val jsontest =
"""{
|"name" : "bob",
|"age" : "50",
|"gender" : "male"
|}
""".stripMargin
val data = parse(jsontest)
but I have received the same error. I am coming from an object oriented programming background, is there something fundamentally wrong with the way I am approaching this problem?
You have most likely incorrectly imported dependencies to your Intellij project or modules into your file. Make sure you have the following lines imported:
import org.json4s.native.JsonMethods._
Even if you correctly import this module, parse(String: json) will not work for you, because you have incorrectly formed a json. Your json String will look like this:
"""{"in_reply_...":"someValue1"}{"in_reply_...":"someValues2"}"""
but should look as follows to be a valid json that can be parsed:
"""{{"in_reply_...":"someValue1"},{"in_reply_...":"someValues2"}}"""
i.e. you need starting and ending brackets for the json, and a comma between each line of tweets. Please read the json4s documenation for more information.
Although being almost 6 years old, I think this question deserves another try.
JSON format has a few misunderstandings in people's minds, especially how they are stored and how they are read back.
JSON documents, are stored as either a single object having all the other fields, or an array of multiple object possibly in same format. this second part is important because arrays in almost every programming language are defined by angle brackets and values separated by commas (note here I used a person object as my single value):
[
{"name":"John","surname":"Doe"},
{"name":"Jane","surname":"Doe"}
]
also note that everything except brackets, numbers and booleans are enclosed in quotes when written into file.
however, there is another use that is not official but preferred to transfer datasets easily where every object, or document as in nosql/mongo language, are stored in a new line like this:
{"name":"John","surname":"Doe"}
{"name":"Jane","surname":"Doe"}
so for the question, OP has a document written in this second form, but tries an algorithm written to read the first form. following code has few simple changes to achieve this, and the user must read the file knowing that:
var json: String = "["
for (line <- io.Source.fromFile("twitter38.json").getLines) json += line + ","
json=json.splitAt(json.length()-1)._1
json+= "]"
val data = parse(json)
PS: although #sbrannon, has the correct idea, the example he/she gave has mistakenly curly braces instead of angle brackets to surround the data.
EDIT: I have added json=json.splitAt(json.length()-1)._1 because the code above ends with a trailing comma which will cause parse error per the JSON format definition.

FabricJS - Error when loading Canvas from JSON

I'm using a custom object extended from fabric.Image in my canvas, as suggested in this answer. When I retrieve the json string from the server, I get odd errors when attempting to load it to the canvas:
var canvas = new fabric.Canvsd();
function loadCanvas(resp) {
// response object contains a data field
// that's essentialy a JSON string
var json = JSON.parse(resp.data);
canvas.loadFromDatalessJSON(json);
}
I get an odd printout to the console: Cannot call method 'setupState' of undefined (fabric.min.js: 1118). I tried replacing the call with canvas.loadFromJSON(json), and instead got a vague SyntaxError: Unexpected token o error. When I used a regular fabric.Image before the change suggested in the linked thread, this code worked fine. I fear this might be something I'm missing when I extended favric's Image class with aditional data. Thoughts?
After some search I saw a similar thread in the fabricjs google group. Turned out I messing up 3 things:
I was missing a fromObject() callback definition in a different location for another custom object I made (I had a couple).
I was using loadFromDatalessJSON() when I should have been using simply loadFromJSON().
I was parsing the json string into an actual JSON using JSON.parse(json) before passing it into the loadFromJSON() function, which expected a json string and handled the parsing internally.
Derp.