dijs / wiki

Wikipedia Interface for Node.js
MIT License
315 stars 61 forks source link

Does not return valid JSON #127

Closed fritzwf closed 4 years ago

fritzwf commented 4 years ago

It doesn't appear to return valid JSON. It looks like it's just returning JavaScript objects using single quotes on the values. It should have double quotes on both the attributes and the values.

dijs commented 4 years ago

Please give some example code.

What page were you testing with? And what do you expect the parser to return.

Thanks

fritzwf commented 4 years ago

I assumed that wikijs is supposed to return JSON, but after looking over the main page and the documentation, I couldn't find anything referencing the return format. When I query the "MST3K" article, the return is:

  showName: 'Mystery Science Theater 3000',
  image: 'MST3K-logo.png',
  showName2: [ 'MST3K', 'MST 3000' ],
  genre: [ 'Comic science fiction', 'Adult puppeteering', 'Film review' ],
  creator: 'Joel Hodgson',
  writer: 'Collapsible list',
  title: 'List of distributors',
  bullets: true,
  presenter: [
    'Joel Hodgson <small>(1988–93)</small>',
    'Michael J. Nelson <small>(1993–99)</small>',
    'Jonah Ray'
  ],
  starring: 'Collapsible list',
  voices: 'Collapsible list',
  themeMusicComposer: [
    'Charlie Erickson <small>(music)</small>',
    'Joel Hodgson <small>(music and lyrics)</small>',
    'Josh Weinstein <small>(lyrics)</small>',
    'Best Brains <small>(lyrics)</small>'
  ],
  opentheme: '"Love Theme from Mystery Science Theater 3000"',
  endtheme: [
    '"Love Theme from Mystery Science Theater 3000" <small>(1988–89)</small>',
    '"Mighty Science Theater"'
  ],
  country: 'United States',
  language: 'English',
  numSeasons: '12',
  numEpisodes: '217',
  listEpisodes: 'List of Mystery Science Theater 3000 episodes',
  executiveProducer: 'Collapsible list',
  producer: 'Kevin Murphy Ivan Askwith David Soldinger Jonah Ray',
  location: [ 'Los Angeles', 'California' ],
  runtime: '92 minutes',
  company: 'Collapsible list',
  distributor: 'Collapsible list',
  network: [
    'WUCW',
    'The Comedy Channel (United States)',
    'Comedy Central',
    'Syfy',
    'Netflix'
  ],
  pictureFormat: [ 'Aspect ratio', 'Standard-definition television' ],
  audioFormat: [ 'Monaural', 'Small', '5.1 surround sound', 'Small' ],
  firstAired: { date: 1988-11-24T00:00:00.000Z },
  lastAired: 'present',
  related: [ 'The Film Crew', 'RiffTrax', 'Cinematic Titanic' ],
  website: 'http://mst3k.com/',
  websiteTitle: 'MST3k Official Site',
  imageSize: '200px'
}

The JSON for the above is:

{
  "showName": "Mystery Science Theater 3000",
  "image": "MST3K-logo.png",
  "showName2": [
    "MST3K",
    "MST 3000"
  ],
  "genre": [
    "Comic science fiction",
    "Adult puppeteering",
    "Film review"
  ],
  "creator": "Joel Hodgson",
  "writer": "Collapsible list",
  "title": "List of distributors",
  "bullets": true,
  "presenter": [
    "Joel Hodgson <small>(1988–93)</small>",
    "Michael J. Nelson <small>(1993–99)</small>",
    "Jonah Ray"
  ],
  "starring": "Collapsible list",
  "voices": "Collapsible list",
  "themeMusicComposer": [
    "Charlie Erickson <small>(music)</small>",
    "Joel Hodgson <small>(music and lyrics)</small>",
    "Josh Weinstein <small>(lyrics)</small>",
    "Best Brains <small>(lyrics)</small>"
  ],
  "opentheme": "\"Love Theme from Mystery Science Theater 3000\"",
  "endtheme": [
    "\"Love Theme from Mystery Science Theater 3000\" <small>(1988–89)</small>",
    "\"Mighty Science Theater\""
  ],
  "country": "United States",
  "language": "English",
  "numSeasons": "12",
  "numEpisodes": "217",
  "listEpisodes": "List of Mystery Science Theater 3000 episodes",
  "executiveProducer": "Collapsible list",
  "producer": "Kevin Murphy Ivan Askwith David Soldinger Jonah Ray",
  "location": [
    "Los Angeles",
    "California"
  ],
  "runtime": "92 minutes",
  "company": "Collapsible list",
  "distributor": "Collapsible list",
  "network": [
    "WUCW",
    "The Comedy Channel (United States)",
    "Comedy Central",
    "Syfy",
    "Netflix"
  ],
  "pictureFormat": [
    "Aspect ratio",
    "Standard-definition television"
  ],
  "audioFormat": [
    "Monaural",
    "Small",
    "5.1 surround sound",
    "Small"
  ],
  "firstAired": {
    "date": "1988-11-24T00:00:00.000Z"
  },
  "lastAired": "present",
  "related": [
    "The Film Crew",
    "RiffTrax",
    "Cinematic Titanic"
  ],
  "website": "http://mst3k.com/",
  "websiteTitle": "MST3k Official Site",
  "imageSize": "200px"
}

It's easy enough to call JSON.stringify(response) to get the JSON. Maybe add something regarding the return data format in the docs?

I have a service that calls wikijs returning JSON: https://tv.feuersoft.com/cgi-bin/get_wiki.cgi?wiki=mst3k

dijs commented 4 years ago

Yes, it is common for javascript libraries to take read/write Object rather than JSON strings. Since it is common practice to gather a value from the object or mutate it in some way.

I would expect a web application to stringify the output of this library before using it as a response to a request. It would not be the job of this library to return JSON directly.

I agree it may not be clear in the docs, but I do mention that it returns an Object here https://dijs.github.io/wiki/WikiPage.html#info

Thanks for using the library!

fritzwf commented 4 years ago

That makes sense. This is a excellent package, thanks for making it!