0

I want to parse a comma separated nested brackets into nested list:

from pyparsing import nestedExpr
str = r'[["http://google.com","Jose Rivas","http://google.com","some_guid"],"a year ago",null,null,4,null,"1003136023",["https://www.yahoo.com","Do it",null,"0ahU_pv"],null,null,"ChZDSUhNMG","0ahUKEwjBr"]'

z = nestedExpr('[', ']').parseString(str).asList()

this is what i get:

enter image description here

why do i get ',' (a single comma) as list item or ,null,null,null, for example? How to fix it?

3
  • Why do you use pyparsing and don't use a usual json package to parse this json? Commented Jan 25, 2021 at 20:19
  • This is not json, json has a name for each variable Commented Jan 25, 2021 at 20:19
  • it's a usual json, try my code in answer block... JSON is dicts + lists Commented Jan 25, 2021 at 20:22

1 Answer 1

1

It's a usual JSON, try to parse it with json package:

import json

raw = r'[["http://google.com","Jose Rivas","http://google.com","some_guid"],"a year ago",null,null,4,null,"1003136023",["https://www.yahoo.com","Do it",null,"0ahU_pv"],null,null,"ChZDSUhNMG","0ahUKEwjBr"]'
data = json.loads(raw)

print(data)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.