Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Looping JSON data
#1
Hi Guys,

I'm trying to loop some JSON which i have created using PHP, sample:

{
    "action": [
        "val1|0|0|val4",
        "val1|val2|0|val4"
    ]
}
I seperate the values using a pipe | which i will then split once i get each line looped, i have so far (very basically):

y = json.loads(_json)
    for line in _json.split(y):
        print(y)
I'm not sure the best weay to go about this, any help would be appreciated.

regards

Graham
Reply
#2
(Jul-01-2019, 08:04 PM)graham23s Wrote: for line in _json.split(y):
If _json is a string, that line should be giving an error. I don't understand what you're trying to accomplish with that, since y is a dict. You should be able to just iterate over the actions directly:
y = json.loads(_json)
if "action" in y:
    for action in y["action"]:
        parts = action.split("|")
        print(parts)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  encrypt data in json file help jacksfrustration 1 185 Mar-28-2024, 05:16 PM
Last Post: deanhystad
  Read nested data from JSON - Getting an error marlonbown 5 1,352 Nov-23-2022, 03:51 PM
Last Post: snippsat
  Reading Data from JSON tpolim008 2 1,073 Sep-27-2022, 06:34 PM
Last Post: Larz60+
  Convert nested sample json api data into csv in python shantanu97 3 2,796 May-21-2022, 01:30 PM
Last Post: deanhystad
  Struggling with Juggling JSON Data SamWatt 7 1,877 May-09-2022, 02:49 AM
Last Post: snippsat
  json api data parsing elvis 0 921 Apr-21-2022, 11:59 PM
Last Post: elvis
  Capture json data JohnnyCoffee 0 1,191 Nov-18-2021, 03:19 PM
Last Post: JohnnyCoffee
  Serializing Python data Correctly (JSON) JgKSuperstar 4 2,077 Nov-04-2021, 07:31 PM
Last Post: JgKSuperstar
  How to save json data in a dataframe shantanu97 1 2,141 Apr-15-2021, 02:44 PM
Last Post: klllmmm
  Sort data from JSON file Dummy_in_programming 2 2,431 Jan-04-2021, 06:17 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020