Re: clojure/data.json parsing
Doh! Of course, what I'm seeing is an artifact of how I'm doing the debug output... arg... I am in the middle of tracking down another issue and I thought the whack output was part of the larger problem. That biased my reading of the output. Sorry for the noise folks, I should be using a logging library anyway. Thanks Tobias and Armando! Grateful to have a helpful community in the face of my obvious lameness :-) Take care. Alan On Saturday, September 27, 2014 3:02:23 PM UTC-7, Armando Blancas wrote: > > Alan, what if you do > (prn orders_query_result) > > If the json string is being parsed correctly you should get string values > printed in double quotes, as Tobias's examples showed. > > On Saturday, September 27, 2014 1:25:27 PM UTC-7, Alan Moore wrote: > >> Yes, I printed the type of body and as expected it is a JSON string and >> as it is printed in the output. That is what I'm trying to parse into >> clojure data using clojure/data.json. >> >> I am not in control of the data format from the server side - it is a >> third party service. The content-type is text/json... :-\ >> >> Thanks for your suggestion. >> >> Alan >> >> >> On Saturday, September 27, 2014 12:31:07 PM UTC-7, Tobias Kortkamp wrote: >>> >>> I hope I understood you correctly. You basically don't want to use >>> println if you want to print data in such a way that it can be read in >>> again. For that you need to use pr, prn or pr-str. >>> >>> Example: >>> >>> (println {:a "hi there"}) will print {:a hi there} >>> >>> (prn {:a "hi there"}) will print {:a "hi there"} >>> >>> (println "Ex: " (pr-str {:a "hi there"})) will print Ex: {:a "hi there"} >>> >>> In other words I suspect that your example's :paymentStatus is the >>> string "QUEUED" already. You can check if a value v is a string with >>> (string? v). >>> >>> -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: clojure/data.json parsing
Alan, what if you do (prn orders_query_result) If the json string is being parsed correctly you should get string values printed in double quotes, as Tobias's examples showed. On Saturday, September 27, 2014 1:25:27 PM UTC-7, Alan Moore wrote: > Yes, I printed the type of body and as expected it is a JSON string and as > it is printed in the output. That is what I'm trying to parse into clojure > data using clojure/data.json. > > I am not in control of the data format from the server side - it is a > third party service. The content-type is text/json... :-\ > > Thanks for your suggestion. > > Alan > > > On Saturday, September 27, 2014 12:31:07 PM UTC-7, Tobias Kortkamp wrote: >> >> I hope I understood you correctly. You basically don't want to use >> println if you want to print data in such a way that it can be read in >> again. For that you need to use pr, prn or pr-str. >> >> Example: >> >> (println {:a "hi there"}) will print {:a hi there} >> >> (prn {:a "hi there"}) will print {:a "hi there"} >> >> (println "Ex: " (pr-str {:a "hi there"})) will print Ex: {:a "hi there"} >> >> In other words I suspect that your example's :paymentStatus is the >> string "QUEUED" already. You can check if a value v is a string with >> (string? v). >> >> -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: clojure/data.json parsing
I am not sure what is going wrong here, and I do not know whether the cheshire library [1] will behave as you wish, but it is worth a try. [1] https://github.com/dakrone/cheshire Andy On Sat, Sep 27, 2014 at 10:24 AM, Alan Moore wrote: > Here is a portion of the data: > > Async HTTP GET: 200 body = { > "count": 1, > "total": 1, > "orders": [ > { > "number": 12, > "vendorNumber": "12", > "created": "2014-09-25 18:25:17", > "paymentStatus": "QUEUED", > ... etc. > > The call (messy from debugging...): > > (let [orderId (Integer/parseInt (:order_id (:params request))) > url (str " > https://app.ecwid.com/api/v1/xxx/orders?STOREID=xxx&secure_auth_key=123&order="; > orderId) > {:keys [body status error]} @(http/get url) > orders_query_result (json/read-str body :key-fn keyword) > order_count (:count orders_query_result) > orders (:orders orders_query_result)] > (if error > (println "Failed, exception is " error) > (doseq [] > (println "Async HTTP GET: " status " body = " body ") > (println "orders_query_result = " orders_query_result) > (println "count = " order_count) > (println "orders = " orders) > (updateOrderPrice (first orders)))... > > This is using http-kit to do an http request to a remote server and that > seems to be working - the body prints out as expected. However, all the > string values are not in quotes: > > orders_query_result = {:count 1, :total 1, :orders [{:taxCost 0.0, > :paymentStatus QUEUED, ... etc. > > The :paymentStatus key is correct but it's value should be "QUEUED", not > QUEUED... > > What am I doing wrong? I could swear I've run across this before and fixed > it but for the life of me I can't find that code anywhere. > > Is there another library I should be using instead? I briefly experimented > with a few others but I really think this should work. > > Alan > > -- > You received this message because you are subscribed to the Google > Groups "Clojure" group. > To post to this group, send email to clojure@googlegroups.com > Note that posts from new members are moderated - please be patient with > your first post. > To unsubscribe from this group, send email to > clojure+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/clojure?hl=en > --- > You received this message because you are subscribed to the Google Groups > "Clojure" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to clojure+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: clojure/data.json parsing
Yes, I printed the type of body and as expected it is a JSON string and as it is printed in the output. That is what I'm trying to parse into clojure data using clojure/data.json. I am not in control of the data format from the server side - it is a third party service. The content-type is text/json... :-\ Thanks for your suggestion. Alan On Saturday, September 27, 2014 12:31:07 PM UTC-7, Tobias Kortkamp wrote: > > I hope I understood you correctly. You basically don't want to use > println if you want to print data in such a way that it can be read in > again. For that you need to use pr, prn or pr-str. > > Example: > > (println {:a "hi there"}) will print {:a hi there} > > (prn {:a "hi there"}) will print {:a "hi there"} > > (println "Ex: " (pr-str {:a "hi there"})) will print Ex: {:a "hi there"} > > In other words I suspect that your example's :paymentStatus is the > string "QUEUED" already. You can check if a value v is a string with > (string? v). > > -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: clojure/data.json parsing
I hope I understood you correctly. You basically don't want to use println if you want to print data in such a way that it can be read in again. For that you need to use pr, prn or pr-str. Example: (println {:a "hi there"}) will print {:a hi there} (prn {:a "hi there"}) will print {:a "hi there"} (println "Ex: " (pr-str {:a "hi there"})) will print Ex: {:a "hi there"} In other words I suspect that your example's :paymentStatus is the string "QUEUED" already. You can check if a value v is a string with (string? v). -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: clojure/data.json parsing
Here is a portion of the data: Async HTTP GET: 200 body = { "count": 1, "total": 1, "orders": [ { "number": 12, "vendorNumber": "12", "created": "2014-09-25 18:25:17", "paymentStatus": "QUEUED", ... etc. The call (messy from debugging...): (let [orderId (Integer/parseInt (:order_id (:params request))) url (str "https://app.ecwid.com/api/v1/xxx/orders?STOREID=xxx&secure_auth_key=123&order="; orderId) {:keys [body status error]} @(http/get url) orders_query_result (json/read-str body :key-fn keyword) order_count (:count orders_query_result) orders (:orders orders_query_result)] (if error (println "Failed, exception is " error) (doseq [] (println "Async HTTP GET: " status " body = " body ") (println "orders_query_result = " orders_query_result) (println "count = " order_count) (println "orders = " orders) (updateOrderPrice (first orders)))... This is using http-kit to do an http request to a remote server and that seems to be working - the body prints out as expected. However, all the string values are not in quotes: orders_query_result = {:count 1, :total 1, :orders [{:taxCost 0.0, :paymentStatus QUEUED, ... etc. The :paymentStatus key is correct but it's value should be "QUEUED", not QUEUED... What am I doing wrong? I could swear I've run across this before and fixed it but for the life of me I can't find that code anywhere. Is there another library I should be using instead? I briefly experimented with a few others but I really think this should work. Alan -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
clojure/data.json parsing
Sorry, it is clojure/data.json that I'm using... sorry for the confusing title. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.