Code Monkey home page Code Monkey logo

jsontocsv's Issues

List ignored

In a complex example one list are ignored

Json to parse (example.json) :

{
   "example":[
      {
         "message":{
            "data":"DATA_1",
            "pages":{
               "pages":[
                  {
                     "lines":{
                        "lines":[
                           {
                              "content":"CONTENT_1_1"
                           },
                           {
                              "content":"CONTENT_1_2"
                           },
                           {
                              "content":"CONTENT_1_3"
                           }
                        ]
                     },
                     "duration":"DURATION_1"
                  }
               ]
            },
            "pictures":"PICTURES_1"
         }
      },
      {
         "message":{
            "data":"DATA_2",
            "pages":{
               "pages":[
                  {
                     "lines":{
                        "lines":[
                           {
                              "content":"CONTENT_2_1"
                           },
                           {
                              "content":"CONTENT_2_2"
                           },
                           {
                              "content":"CONTENT_2_3"
                           }
                        ]
                     },
                     "duration":"DURATION_2"
                  }
               ]
            },
            "pictures":"PICTURES_2"
         }
      }
   ]
}

Parse string :

PARSE_STR = '''
        +"example"[
            ."message"[
                "data",
                "pictures"
                ."pages"[
                    +"pages"[
                        "duration"
                        ."lines"[
                            +"lines"[
                                "content"
                            ]
                        ]
                    ]
                ]
            ]
        ]
'''

Python Code

with open('example.json', 'rt') as f:
  contents = f.read()
  parser = JsonToCsv(PARSE_STR, nullValue=NULL_VALUE, debug=IS_DEBUG)
  csvDataStr = parser.convertToCsv(contents)

output (second content list are ignored) :

DATA_1,PICTURES_1,DURATION_1,CONTENT_1_1
DATA_1,PICTURES_1,DURATION_1,CONTENT_1_2
DATA_1,PICTURES_1,DURATION_1,CONTENT_1_3
DATA_2,PICTURES_2,DURATION_2

expected output :

DATA_1,PICTURES_1,DURATION_1,CONTENT_1_1
DATA_1,PICTURES_1,DURATION_1,CONTENT_1_2
DATA_1,PICTURES_1,DURATION_1,CONTENT_1_3
DATA_2,PICTURES_2,DURATION_2,CONTENT_2_1
DATA_2,PICTURES_2,DURATION_2,CONTENT_2_2
DATA_2,PICTURES_2,DURATION_2,CONTENT_2_3

Not being able to parse "first level lists"

I am trying to parse a json that consists in a list of maps such as [{"a":"1}, {"a":3}] but I am not being able to define the parse string for it. A simple + demands a key, which means that this list would need to be contained in a map. Am I missing something?

Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.