Sam DeHaan
Sam DeHaan

Reputation: 10325

Parsing Objects in non-standard format

I have a scala graph theory project I've been assigned, and the input is in a strange, not-quite-JSON format.

It is similar to a Java Properties style file, but the edges List does not parse well using that class. I have searched to the best of my ability to find a similar file format online with no success.

Is there any simple way to parse input like the following?

startValue: "location 1"

endValue: "location 3"

edges: 

List(
  Map("startLocation" -> "location 1", "endLocation" -> "location 2", "distance" -> 6),
  Map("startLocation" -> "location 1", "endLocation" -> "location 3", "distance" -> 2),
  Map("startLocation" -> "location 1", "endLocation" -> "location 4", "distance" -> 4),
  Map("startLocation" -> "location 2", "endLocation" -> "location 3", "distance" -> 2),
  Map("startLocation" -> "location 2", "endLocation" -> "location 4", "distance" -> 6),
  Map("startLocation" -> "location 3", "endLocation" -> "location 4", "distance" -> 3)
)

Upvotes: 0

Views: 65

Answers (1)

Sathya
Sathya

Reputation: 111

Make a shell script or script from any other scripting language that copies the code from "edges" section and pastes in a scala file. The resulting scala file may look like,

object Edge{
  val edges = /**Test under the edges section**/
}

You can access the list by "Edge.edges".

Upvotes: 1

Related Questions